fix(web): keep escaped-bracket footnotes across PR attachments #47870
main fromrefs/pull/47870/head·merged by juliusmarminge View on GitHubProblem#
In PR descriptions and comments rendered through PullRequestMarkdown → splitPullRequestBody → wordsHast, a footnote whose label contains an escaped square bracket (such as [^a\[b] or [^a\]b]) stops linking and its note disappears when a lifted video sits between the citation and definition. markdownFootnoteLabels in apps/web/src/markdown/wordsHast.ts prefilters candidate labels with /\[\^([^\s[\]]+)\]:/g, which excludes all square brackets including escaped ones that @pierre/words accepts.
Deterministic repro on origin/main (baf8956263d5dfcafb3ce6396144a8edde347389):
- Fixture: pass
"See[^a\\[b].\n\nhttps://github.com/user-attachments/assets/a.mp4\n\n[^a\\[b]: note"(or witha\\]b) tosplitPullRequestBody, then render its Markdown segments withwordsHast. - Command:
vp test run apps/web/src/components/pullRequest/pullRequestMarkdown.logic.test.ts -t "keeps a footnote with an" - Observed on
origin/main:splitPullRequestBodyreturns segments withfootnotes: undefinedand no trailing"only"segment; rendering the citation segment emits zerodataFootnoteRefanchors and the note disappears. - Expected:
splitPullRequestBodyinstalls footnote stubs (footnotes: "omit") and appends the trailing"only"footnote segment so the citation links to#user-content-fn-1and the note renders, matching the unsplit body.
Change#
Update the candidate label scan in markdownFootnoteLabels (apps/web/src/markdown/wordsHast.ts) from /\[\^([^\s[\]]+)\]:/g to /\[\^((?:[^\s\\[\]]|\\.)+)\]:/g so escaped characters (including \[, \], and \\) are consumed atomically while preserving the authored escapes and keeping Words' lookup as the validity check. Added regression cases for escaped opening brackets, escaped closing brackets, and escaped trailing backslashes across a lifted video in apps/web/src/components/pullRequest/pullRequestMarkdown.logic.test.ts.
This covers both Web and Electron PR detail views, which share PullRequestMarkdown and wordsHast (mobile does not split footnotes across attachments).
Scope#
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification#
- Base failure (
baf8956263d5dfcafb3ce6396144a8edde347389):vp test run apps/web/src/components/pullRequest/pullRequestMarkdown.logic.test.ts -t "keeps a footnote with an"failed on bothescaped opening bracketandescaped closing bracket(expected [ [ 'markdown', undefined ], …(2) ] to deeply equal [ [ 'markdown', 'omit' ], …(3) ]). - Head pass (
27f51bd21e0064e5a063289e2a99caa4d5007511): the same targeted command passed (3/3 cases), andvp run check:changedexited0(format,lint,knip,typecheckon 2 packages,teston 2 files / 121 tests,react compileron 1 file). - Before/after transcript: https://gist.github.com/saphid/f9c9ea7e03843a1fde84259f1eb9e881
- Not shown: live browser/Electron UI screenshot of a rendered PR detail view (the bug is purely in
markdownFootnoteLabels's regex prefilter and is deterministically verified throughsplitPullRequestBody+wordsHast).
Authored by Gemini 4 Neon (Antigravity); reviewed by GPT-6.2 Sol (Codex).
Not shown#
- apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx:1122 — The transcript is unit-level only; add before/after screenshots of a rendered PR description with an uploaded video, showing the literal citation and missing note on base versus the link and visible note on head.
- apps/web/src/components/pullRequest/pullRequestMarkdown.logic.test.ts:121 — The test command is deterministic but not a scenarios:prove repro. Add a real-app fixture that seeds the PR description, opens the PR detail view, and asserts the citation href and matching note target.
- apps/web/src/markdown/wordsHast.ts:1454 — The gist shows targeted base/head results, not the reported check:changed run. Attach its exit-0 transcript with the reviewed HEAD SHA if independent verification is needed.
- apps/mobile/src/features/pull-requests/PullRequestMarkdown.tsx:128 — Mobile does split the body around attachments; it uses a separate native renderer without this footnote-reassembly path. Clarify the scope sentence accordingly.
- 1
- 2
Pushede20daa2
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Evidence#
Steps on both commits: seed the Footnotes project; open
scenario/footnotes#7; renderSee[^a\\[b]., a blank line, a local placeholder video attachment, a blank line, and[^a\\[b]: note; wait forSee; capture; assert onea[data-footnote-ref]and a footnotes section containingnote.Base 4fec70c4baHead e20daa226dResult ❌ Failed: a[data-footnote-ref]count was 0; the citation stayed literal and the note was absent.✅ Passed: one numbered footnote link rendered and 1. noteremained below the video.Capture 

juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged this3067c49
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes