Summary
Fallback selectors emitted in Context Packets can fail to identify the selected element.
Root cause
packages/core/src/context.ts, buildElementSelector(), computes a document-global index among annotated elements of the same tag and emits :nth-of-type(index). CSS nth-of-type() is sibling-relative, not document-global.
For repeated tags under different parents, generated selectors can match nothing or the wrong element. The method also scans every same-tag element for each packet.
Proposed fix
- Prefer unique
id and data-askable-id.
- Otherwise construct a parent-relative selector path using sibling-local indexes.
- Validate that the selector resolves uniquely to the original element before returning it.
- Avoid a document-wide same-tag scan.
Acceptance criteria
Summary
Fallback selectors emitted in Context Packets can fail to identify the selected element.
Root cause
packages/core/src/context.ts,buildElementSelector(), computes a document-global index among annotated elements of the same tag and emits:nth-of-type(index). CSSnth-of-type()is sibling-relative, not document-global.For repeated tags under different parents, generated selectors can match nothing or the wrong element. The method also scans every same-tag element for each packet.
Proposed fix
idanddata-askable-id.Acceptance criteria
data-askable-idvalues do not produce a falsely unique selector