Skip to content

fix(core/link-to-dfn): use parentElement.closest() for scoping hint#5261

Open
marcoscaceres wants to merge 3 commits intospeced:mainfrom
marcoscaceres:fix/5257-closest-self-match
Open

fix(core/link-to-dfn): use parentElement.closest() for scoping hint#5261
marcoscaceres wants to merge 3 commits intospeced:mainfrom
marcoscaceres:fix/5257-closest-self-match

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

Closes #5257

`elem.closest("[data-link-for]")` matches the element itself, so when an `` has `data-link-for` (e.g., from `[=bar/foo=]` syntax), the hint incorrectly says the link is "inside" a scoped section when the attribute is on the link itself.

Uses `parentElement.closest()` to restrict to ancestor elements. Also guards against the empty-string case (`data-link-for=""` means intentionally unscoped).

`elem.closest("[data-link-for]")` matches the element itself, so when
an `<a>` has `data-link-for` (e.g., from `[=bar/foo=]` syntax), the
hint incorrectly says the link is "inside" a scoped section when the
attribute is on the link itself.

Use `parentElement.closest()` to restrict to ancestor elements. Also
guard against the empty-string case (`data-link-for=""` means
intentionally unscoped).

Closes speced#5257
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an incorrect scoping hint emitted by core/link-to-dfn when reporting unresolved links, ensuring the hint only considers ancestor [data-link-for] scopes (not the <a> itself) and suppresses the hint for intentionally-unscoped data-link-for="".

Changes:

  • Scope detection now uses elem.parentElement?.closest("[data-link-for]") to avoid closest() matching the anchor itself.
  • Scoping note now only appears when the found scoped ancestor has a non-empty data-link-for value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/link-to-dfn.js Outdated
Comment thread src/core/link-to-dfn.js
Address Copilot feedback:
- Add `?? null` to normalize `undefined` from optional chaining to
  `null`, matching the JSDoc type `HTMLElement | null`
- Add test covering all 3 scoping hint cases: non-empty ancestor
  data-link-for (hint fires), empty data-link-for (hint omitted),
  and no data-link-for (hint omitted)
@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

1 similar comment
@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

@marcoscaceres marcoscaceres marked this pull request as ready for review May 4, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: closest('[data-link-for]') in scoping hint can match the anchor itself

2 participants