Skip to content

fix(shared): Markdown previews keep first references with next-line destinations - #43807

Merged
juliusmarminge merged 12 commits into
pingdotgg:mainfrom
StiensWout:wf/find-552abf86acc5526378e702e1
Nov 26, 2026
Merged

juliusmarminge merged 12 commits into
pingdotgg:mainfrom
StiensWout:wf/find-552abf86acc5526378e702e1

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Chunked Markdown previews could open a later URL when the first reference definition put its destination on the next line. The chunker now collects complete definitions in document order using bounded batches and preserves their labels, destinations, and titles. It distinguishes a separate quote-led paragraph from a continued title and keeps later duplicates from overriding a confirmed oversized title in its source chunk.

Related: #43647, #43654, #23503, #43673, #43709, #43711

Reproduction on main

Commit f08bafe07f (main), in the running web app:

  1. Start the web app and open a project.
  2. Open a Markdown file from the project files. If the project has none, add one.
  3. Replace the file with these lines, then save it: a line [Release notes][release], a blank line, a line [release]:, a line of two spaces then https://example.com/current, a blank line, a line Notes., a blank line, a line ## Appendix, a blank line, and a line [release]: https://example.com/previous.
  4. Open that file in the preview if it is not already open, and press Show rendered markdown.
  5. Press the Release notes link.

The link opens https://example.com/previous, the address from the later one-line reference. Expected: The link opens https://example.com/current, the address from the first reference.

The cause is at packages/shared/src/markdownChunks.ts:180. Ran pnpm scenarios:prove scripts/scenarios/markdown-first-multiline-definition.e2e.ts --target web with the repro scenario added: it failed in 2 of 2 runs on a clean checkout, with expect.toHaveAttribute failed in the output.

Evidence

Environment: The web app in Chromium on Linux x64, a fresh checkout.

Proven: the repro fails at the test commit 91523cf9fc and passes on the head 14abf45ce3, both on main 6252f1f203.

Before After
Commit 91523cf9fc 14abf45ce3
Result ASSERTION_FAILED: expect.toHaveAttribute failed passed
first reference Before: first reference After: first reference
failure Before: failure

Before the fix, recorded:

https://pub-b182a4071edc4521829926b34990540b.r2.dev/files/0f552df4-d97a-4904-a206-605fc6507b1c/before-recording.webm

After the fix, recorded:

https://pub-b182a4071edc4521829926b34990540b.r2.dev/files/0b73322e-d838-4806-b7e8-bcd646bc7e69/after-recording.webm

Outside view: a person sees it in the running web app by following the steps under Reproduction on main.

Tests

  • 91523cf9fc adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed 6252f1f203f389b9c8aa2f41b4d415324e8d1fd9 passed on head.

Not in this change

  • Sharing applies to top-level link definitions within the preview’s size budget. Oversized definitions resolve in their source chunk.
  • Footnotes resolve within their own chunks.

Who did the work

  • Repro written by GPT 6.2 Sol, in Codex
  • Outside view by Grok 4.7, in Grok
  • Duplicate check judged by Claude Opus 5.5, in Claude Code
  • Written by GPT 6.2 Sol, in Codex
  • Trimmed by Claude Opus 5.5, in Claude Code
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex, and by Gemini 4 Neon, in Antigravity
  • Reproduction, checks and proof run by a program on base and head, not by an agent

Made in T3 Code by GPT 6.2 Sol, Claude Opus 5.5, Grok 4.7 and Gemini 4 Neon

StiensWout and others added 11 commits November 26, 2026 23:35
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…estinations

Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…a duplicate parameter

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…y passes

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…otnote comment as it was

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…at uses it

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…oving it

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 14abf45 and aacc95e.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

Markdown splitting now uses Remark to collect eligible link reference definitions across multiple lines. It tracks definition spans and applies the existing 16 KiB shared-definition limit. Tests cover parsing, chunking, and rendered link destinations.

Changes: Markdown reference definitions

Layer / File(s) Summary
Parse reference definition runs
packages/shared/src/markdownChunks.ts
Remark parsing identifies link definitions and their source spans. Run scanning recognizes definition boundaries, display-math openers, and the shared-definition size limit.
Integrate definition spans and validate rendering
packages/shared/src/markdownChunks.ts, packages/shared/src/markdownChunks.test.ts, scripts/scenarios/markdown-first-multiline-definition.e2e.ts
splitMarkdown tracks parsed definition spans and omits definitions that exceed the shared limit. Unit and end-to-end tests cover multiline definitions, chunk boundaries, and rendered links.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge, saphid

Merge Risk: Minimal · previous review 14abf

Markdown previews now resolve multiline link reference definitions to the first definition's destination. No concrete merge-blocking risk was identified, and the change is easy to revert if needed.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix and its scope: Markdown previews in the shared package now keep the first link reference when its destination is on the next line. The changeset adds multiline reference-defini…
Description check Passed The description follows the template's sections (Problem, Change, Scope, Verification) and fills them with specific content. The Problem is covered by the reproduction steps and the expected behavior.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix and its scope: Markdown previews in the shared package now keep the first link reference when its destination is on the next line. The changeset adds multiline reference-definition parsing in markdownChunks.ts and a matching test, so the title covers the main change. It is 80 characters, slightly long but within a readable range, and it follows the conventional commit format.

Full details: Description check

Explanation

The description follows the template's sections (Problem, Change, Scope, Verification) and fills them with specific content. The Problem is covered by the reproduction steps and the expected behavior. The Change explains the bounded batch collection, label, destination, and title preservation, and the quote-led paragraph distinction. The Scope links related issues and the Verification section gives concrete commands, commit hashes, and before/after results. Minor gaps: the Problem section is not a separate heading with a one or two sentence statement, and the Scope section does not state explicitly why the change is a bug fix rather than a feature. The Verification section also lists tests run, and the 'Not in this change' section is an extra section not in the template. These gaps are non-critical, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a4ab2c5 and 14abf45.

Files selected for processing: 3

  • packages/shared/src/markdownChunks.test.ts
  • packages/shared/src/markdownChunks.ts
  • scripts/scenarios/markdown-first-multiline-definition.e2e.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 26, 2026
@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Created the reported long Markdown document with a next-line first reference destination and a later one-line duplicate. Opened its rendered file preview and hovered Release notes. Environment on both sides: Chromium, 1280×800, light theme, fresh database, synthetic project and Replay thread.

The scenario runner exited 0: base used https://example.com/previous; head used https://example.com/current. Both the app tooltip and anchor href confirmed the difference.

Before After
Before: incorrect previous destination After: correct first destination
dcee01cbfd aacc95e326
Before recording After recording

Scenario source

Not shown:

  • Multiline reference labels and titles were not exercised; this scenario covers the reported next-line destination and duplicate-definition ordering across preview chunks.
  • The short-file variant was not separately exercised.
  • External-tab navigation was not clicked; the app's visible tooltip and actual anchor href were checked on both commits.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 26, 2026
@juliusmarminge
juliusmarminge merged commit 3ebc46f into pingdotgg:main Nov 26, 2026
60 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 26, 2026
juliusmarminge added a commit to StiensWout/t3code that referenced this pull request Nov 26, 2026
…prose once

Main's remark-based definition reader (pingdotgg#43807) already rejects invalid labels, so it replaces this branch's one-line matcher. Kept the label tests, kept definition indentation so tabbed labels keep their width, and dropped the scenario that main now passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot pushed a commit to Ryoku-dev/hyakki that referenced this pull request Nov 27, 2026
…estinations (pingdotgg#43807)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
(cherry picked from commit 3ebc46f)
github-actions Bot pushed a commit to Ryoku-dev/hyakki that referenced this pull request Nov 27, 2026
…estinations (pingdotgg#43807)

Co-authored-by: Julius Marminge <julius0216@outlook.com>
(cherry picked from commit 3ebc46f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants