fix(core/link-to-dfn): incorporate data-dfn-for into generated IDs#5283
fix(core/link-to-dfn): incorporate data-dfn-for into generated IDs#5283marcoscaceres wants to merge 9 commits into
Conversation
When a dfn has a data-dfn-for attribute, include the for-context in the generated ID. This produces semantically meaningful IDs like dfn-wall-clock-unsafe-current-time instead of dfn-unsafe-current-time-0 when multiple dfns share the same text but target different interfaces. Closes #4415
|
@copilot Can you fix the issue identified by ci? |
Fixed in d5aa6cb. I addressed the CI failures by updating the affected xref/location-hash expectations for data-dfn-for-based IDs and adding a legacy hash fallback so old internal-slot fragments resolve to the new contextual dfn IDs. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot CI is failing with one test:
Test: |
There was a problem hiding this comment.
Pull request overview
This PR updates ReSpec’s local definition linking so that auto-generated <dfn> IDs incorporate the data-dfn-for context, aiming to avoid numeric suffixes when multiple definitions share the same text but differ by “for” context (per #4415).
Changes:
- Generate
<dfn>IDs using${dfnFor}-${title}(whendata-dfn-foris present) instead of${title}. - Extend
core/location-hashlegacy-fragment recovery to also try matchingdfn-*-${term}-style IDs when the exact legacy ID can’t be found. - Update affected core spec tests to assert the new fragment IDs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/core/link-to-dfn.js |
Changes generated <dfn> IDs to include data-dfn-for context. |
src/core/location-hash.js |
Adds recovery logic for legacy dfn-* fragments when IDs have changed. |
tests/spec/core/link-to-dfn-spec.js |
Updates expectations for new dfn-${for}-${title} fragments. |
tests/spec/core/location-hash-spec.js |
Updates the slot legacy-hash recovery test for the new ID format. |
tests/spec/core/xref-spec.js |
Updates xref expectations to reflect new local internal-slot fragment IDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const idText = dfnFor ? `${dfnFor}-${title}` : title; | ||
| addId(dfn, "dfn", idText); |
| const termWithLeadingHyphen = `-${id.slice(DFN_ID_PREFIX.length)}`; | ||
| const matchingElements = [ | ||
| ...document.querySelectorAll( | ||
| `[id^='${DFN_ID_PREFIX}'][id$='${CSS.escape(termWithLeadingHyphen)}']` | ||
| ), | ||
| ]; | ||
| if (matchingElements.length === 1) { |
| const a = doc.getElementById("testAnchor"); | ||
| expect(a).toBeTruthy(); | ||
| expect(a.hash).toBe("#dfn-test"); | ||
| expect(a.hash).toBe("#dfn-window-test"); | ||
| const decodedHash = decodeURIComponent(a.hash); | ||
| expect(doc.getElementById(decodedHash.slice(1))).toBeTruthy(); |
| const doc = await makeRSDoc(ops, testURL); | ||
| expect(doc.location.hash).toBe("#dfn-escapedslot"); | ||
| expect(doc.location.hash).toBe("#dfn-test-escapedslot"); | ||
| }, 20000); |
Fixed in a697576. I updated Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot make the fixes you suggested. |
Done in 5ffd7c7. I implemented the suggested follow-ups: numeric legacy fragment recovery now handles Validated locally with:
Screenshot: N/A (no UI changes). Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Closes #4415
Include the data-dfn-for context in generated IDs to produce
meaningful names instead of numeric suffixes when multiple dfns
share the same text.