Repository navigation
fix(markdown): footnote ids are unique per answer - #159
Merged
Merged
Conversation
…its own footnote @tanstack/markdown 1.0.0 hardcodes user-content-fn-*, user-content-fnref-* and footnote-label, so two answers using [^1] on one page share ids and every ref and backref jumps into the first. Each Markdown root now prefixes those ids with useId, which matches between server and client. The docs demo gains a footnote so the page shows two blocks using [^1].
Owner
Author
|
Verifier: PASS+NOTES at 3608755. check, build, test (544 pass) re-run on an export; browser lane on static build: block 2 ref and backref stay in block 2, server ids match hydrated, 1 of 84 prerendered pages changed (footnote ids only). Notes, not blocking: heading slug ids still repeat across blocks; no scroll-padding-top under the sticky header; markdown.md 'Links open in a new tab' is stale since #141. Queued as a follow-up. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Goal: fix every bug on
ui-sdkthat can be fixed on our side before it lands on main.When two answers on one page both use
[^1], every footnote link and back-link jumps into the first answer. @tanstack/markdown 1.0.0 hardcodes the idsuser-content-fn-*,user-content-fnref-*andfootnote-label(dist/react.js:57-60, 142, 167). It has no prefix option. A document transform could rename the footnote ids, butfootnote-labelis a fixed string, so it can't reach that one.What
Markdowntakes auseIdprefix and passes it down through context. Thea,h2andlioverrides add it to the footnote ref, the backref, the Footnotes heading and the footnote items.useIdgives the same value on the server and the client, so the prerendered HTML hydrates as is.[^1].Verification
two answers that both use [^1] keep their footnotes apart. It checks that the 6 ids are unique, that each ref's href resolves to anliinside its own block, that the backref returns to that ref, and thataria-describedbynames its own block's heading. It fails on the start SHA (1 failed, 5 passed) and passes with the fix.vpr check,vpr buildandvpr testpass on the head (67 files, 544 passed, 1 expected fail)./docs/components/markdown, light and dark, with no console errors. Clicking ref 1 in block 2 goes to#_R_5eb6aq_user-content-fn-1. That target is inside block 2, not block 1, and the page scrolls it to the top. The backref goes back to block 2's ref. The page stays in the tab, and the heading is still 1px wide. The ids in the server HTML match the ids after hydration.Tradeoffs
a,h2orlithroughcomponentsalso replaces the prefixing. That's the same contract as the existing overrides._R_xxx_user-content-fn-1, so an outside link to#user-content-fn-1stops working. There are no users yet.Tracker
useId. Fixed here.monthly-active-users) still repeat across blocks. It's the same bug class, but in heading ids.scroll-padding-top, so any hash target, footnotes in block 1 included, lands under the 64px sticky header.