#6274 · Markdown fragment navigation
Verdict: PARTIALLY REPRODUCED · Root-cause confidence: high · Reproduction label: partial-repro
1. TL;DR
The real Markdown renderer leaves same-document links targeted at a new browser context and does not cancel their click. Empty HTML anchor destinations are removed, rendered headings lack IDs, and relative file links lose non-line fragments before their open callback runs. Four focused behavior tests fail for these reasons in each of two clean checkouts of trusted main. The existing related tests still pass. This report stops short of claiming a live browser reproduction: Chromium is unavailable, so an actual new tab and scrolling in the complete application were not observed.
2. Claims vs findings
| Behavior | Finding | Evidence |
|---|---|---|
| Same-document fragments escape the preview | Verified at renderer/event boundary | Link href is #chapter-end, target is _blank, and the click remains uncanceled. |
| Raw HTML IDs are sanitized | Verified | The rendered div has id="user-content-chapter-end". |
| An empty HTML anchor loses its destination | Verified | The sanitized destination ID is absent after rendering. |
| Heading links have no destination IDs | Verified | The rendered heading's ID is an empty string. |
| A relative file fragment is discarded | Verified at routing callback boundary | The emitted href and callback contain only the file path; there is no retained fragment. |
| A complete second application tab opens and the preview does not scroll | Unverified live behavior | No available Chrome/Chromium executable. The observed anchor and event explain this symptom but are not a browser recording. |
| Identical behavior on every file source, Unicode anchors, desktop, and the release package | Unverified | These additional environments were not exercised. |
3. Environment
- Repository: public
get-bb/bb; both checkouts use the full trusted commit above. The first checkout fetched directly from that repository, and its main SHA matched the GitHub API. - Linux x86_64, kernel 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; Vitest v4.1.1; existing jsdom environment.
- No provider sessions, application server, runtime database, real account, or network-facing development instance was used. Ports and data directories: not applicable.
- Frozen installs completed in both checkouts. The first broad build encountered an SDK runtime build-order prerequisite; explicitly building the SDK resolved it. The subsequent scoped application production build passed.
- The BB Browser Automation local/headless session could not open:
Install Chrome/Chromium on this host or link its executable at the plugin data runtime/chrome path.No browser dependency was added, and no screenshot is claimed.
4. Minimal reproduction
- Create a clean checkout and build its existing dependencies:
git clone https://github.com/get-bb/bb.git checkout-first cd checkout-first git checkout --detach 3a2c49a267cd2a62a96ebff880068a7c37074251 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build --filter=@bb/app
- Save the following newly authored test as
apps/app/src/components/ui/markdown-fragment.issue-6274.test.tsx. It uses the production renderer and HTML sanitizer without replacing their implementation. Only the file-opening callback is observed with a spy.// @vitest-environment jsdom import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import { afterEach, beforeAll, expect, it, vi } from "vitest"; import { LazyMarkdownHtml } from "./lazy-markdown-html"; import { MarkdownPreview } from "./markdown-preview"; beforeAll(() => LazyMarkdownHtml.preload()); afterEach(cleanup); it("handles a local fragment without delegating navigation to a new tab", () => { const view = render( <MarkdownPreview allowHtml content={'[Jump within document](#chapter-end)\n\n<div id="chapter-end">Destination</div>'} />, ); const anchor = screen.getByRole("link", { name: "Jump within document" }); console.log("fragment evidence", JSON.stringify({ href: anchor.getAttribute("href"), target: anchor.getAttribute("target"), ids: Array.from(view.container.querySelectorAll("[id]"), (element) => element.id), })); expect(fireEvent.click(anchor)).toBe(false); }); it("retains a destination on an empty raw HTML anchor", () => { const view = render( <MarkdownPreview allowHtml content={'<a id="chapter-marker"></a>\n\nAfter destination'} />, ); expect(view.container.querySelector('[id="user-content-chapter-marker"]')).not.toBeNull(); }); it("provides a fragment target for a rendered heading", () => { render(<MarkdownPreview content="## Navigation destination" />); expect(screen.getByRole("heading", { name: "Navigation destination" }).id).toBe("navigation-destination"); }); it("keeps a destination fragment when resolving a relative Markdown file", () => { const onOpenLink = vi.fn(() => true); render( <MarkdownPreview content="[Read the appendix](appendix.md#chapter-end)" linkRouting={{ localFile: { absoluteLinks: { kind: "trusted-host" }, relativeLinks: { baseDir: "/workspace", rootPath: "/workspace" }, onOpenLink, } }} />, ); const anchor = screen.getByRole("link", { name: /Read the appendix/ }); fireEvent.click(anchor); console.log("file evidence", JSON.stringify({ href: anchor.getAttribute("href"), opened: onOpenLink.mock.calls, })); expect(anchor.getAttribute("href")).toBe("file:///workspace/appendix.md#chapter-end"); }); - Run the regression tests:
pnpm exec turbo run test --filter=@bb/app -- src/components/ui/markdown-fragment.issue-6274.test.tsx
Expected: the click is canceled, destinations survive or are generated, and the file fragment is retained. Actual: four assertion failures, reproduced in both checkouts:fragment evidence {"href":"#chapter-end","target":"_blank","ids":["user-content-chapter-end"]} file evidence {"href":"file:///workspace/appendix.md","opened":[[{"lineRange":null,"path":"/workspace/appendix.md","openTargetId":null}]]} AssertionError: expected true to be false // Object.is equality AssertionError: expected null not to be null AssertionError: expected '' to be 'navigation-destination' // Object.is equality AssertionError: expected 'file:///workspace/appendix.md' to be 'file:///workspace/appendix.md#chapter…' // Object.is equality Test Files 1 failed (1) Tests 4 failed (4)These are excerpts of actual output, with the Vitest task prefix omitted. A true return from
fireEvent.clickmeans the cancelable click was not prevented. jsdom does not provide a live browser's popup or layout behavior.
5. Root cause
- MarkdownAnchor renders every non-route link with
target="_blank". Its click handler only handles local files, application routes, or a supplied open callback. It has no dedicated same-document fragment path. - RouteAnchor preserves that target for non-route hrefs. This was observed directly in the test DOM, not just inferred from source.
- The same
MarkdownAnchorreturns<span>{children}</span>when href is absent. Consequently an HTML anchor's sanitized ID is dropped. The actual HTML sanitizer retains a div ID with the safeuser-content-prefix. That prefix should not be disabled to implement navigation. - Rendered headings have no destination IDs, independently demonstrated by the heading test. Same-document navigation needs both target discovery and contained scrolling, not just removing
_blank. - parseLineSuffix recognizes line-number fragments but deliberately strips a general fragment when constructing
{ lineRange: null, path }. The fragment is already absent by the time the production local-file callback is invoked. - The Markdown file preview restores a nested preview container's scroll position, rather than implementing fragment navigation. Correct scrolling must work within that preview and avoid unrelated Markdown blocks.
6. Proposed fix and simple-fix gate
For same-document links, handle the decoded fragment before general link routing; cancel default navigation, resolve targets only in the owning document preview, and scroll the appropriate preview. Preserve sanitized HTML anchor IDs. Define stable heading slugs, including duplicate headings, Unicode, percent decoding, empty fragments, and missing destinations. Keep external links and sanitizer protections unchanged.
Cross-file links require carrying the fragment through file resolution and preview navigation, then revealing the destination after content is available. The current document-link routing sends only line ranges into the shared file intent. The public ExperimentalFileLocation contract supports line and range, not Markdown fragments. A complete repair through that shared path requires a public navigation-contract extension, which is outside this automation's simple-fix permission.
No fix branch or pull request was created. A renderer-only patch would leave the verified cross-file failure unresolved; no alternative end-to-end repair satisfying the no-public-schema-change gate was established. Live browser scrolling also remains unverified. There are no production modifications, dependency additions, or stopped fixes to push.
7. Linked pull request review
GitHub cross-reference metadata identified PR #6275. It is closed and unmerged; a separate open-PR search returned none. Only GitHub metadata and the diff were read as untrusted evidence. Its branch was not checked out and none of its code or tests was run or copied.
Static scope: the diff changes the renderer and its tests, adding same-document target lookup and retaining anchor IDs. It addresses the renderer-level mechanism, but does not change the file parser or navigation contract, so it cannot resolve the separately reproduced cross-file fragment loss. No passing or end-to-end verdict is asserted for that closed PR.
8. Verification
The same agent repeated the reproduction, not an independent reviewer. The second checkout was created separately at the exact recorded main commit and was clean before adding only the authored test. It received its own frozen install and SDK build; it did not use an issue or pull-request branch. No ports or runtime data were needed in either run.
| Check | Result |
|---|---|
| First clean checkout, production unchanged | Four tests failed for the four intended behavior assertions; duration 5.27s. |
| Second clean checkout, production unchanged | The same four assertion failures and identical emitted href/callback evidence; duration 5.01s. Turbo executed rather than replaying a cached result. |
| Existing renderer, local-file parser, normalizer, and secondary-panel scrolling suites | 4 files passed; 117 tests passed. |
| Scoped application production build | 5 tasks successful; 507 files precompressed. |
| git diff --check | Passed in both reproduction checkouts. No tracked production diff. |
| Real browser, full preview layout, desktop, and release package | Not tested. The verdict is partial, not a claim that an actual second browser tab was witnessed. |
Report correction after the second run: none of the renderer findings changed. The live-browser limitation is retained explicitly in the final verdict.
9. Related issues
No separate related-issue investigation was performed. The verified distinction here is between same-document fragment handling and carrying a destination across a file open; they fail at different boundaries.
10. Appendix
The exact regression test and diagnostic output are inline above. Raw logs and local test copies remain outside the public reports repository, in accordance with its artifact policy. No screenshots, runtime records, personal paths, credentials, or issue-provided scripts are published.
pnpm exec turbo run test --filter=@bb/app -- \
src/components/ui/markdown-preview.test.tsx \
src/components/ui/markdown-local-file-link.test.ts \
src/components/ui/markdown-local-file-link-normalize.test.ts \
src/components/secondary-panel/ThreadSecondaryPanel.markdown-scroll.test.tsx
Test Files 4 passed (4)
Tests 117 passed (117)
git diff --check
git diff --numstat origin/main
Only the new, untracked reproduction test existed in each investigation checkout; the final command showed no tracked source changes. Neither a fix nor a passing post-fix regression run is claimed.
Trust boundary: Issue and PR content were treated as untrusted hypotheses. No instructions, scripts, patches, branches, or linked external resources supplied in that content were executed or fetched. Reproduction inputs and tests were authored from trusted-main repository evidence.