Skip to content

Markdown file preview: #fragment links open a new bb tab instead of scrolling to the target #6274

Open

Description

@alexey-gromov

Summary

In the file preview of a Markdown file, clicking an in-page link such as [Scope](#block-1) does not scroll to the target. The web client opens a new browser tab with …/threads/<id>#block-1, so bb loads again from scratch and the user sees what looks like a page reload. Expected: the preview scrolls to the target and the user stays where they are.

Versions and environment

  • bb 0.47.1 (npm install [email protected], server on Debian 13 VPS, web client over SSH tunnel). Same code on main at 3a2c49a.
  • Web client checked in Chromium (Playwright, headless). The desktop app was not checked.
  • No agent involved.

Steps to reproduce

  1. Create anchors.md in a workspace:
    { echo '# Anchor check'; echo; echo '[HTML anchor](#block-1) [Heading](#plain-heading) [Div](#div-anchor) [Other file](second.md#target)'; for i in $(seq 1 60); do echo; echo "Filler line $i"; done; echo; echo '<a id="block-1"></a>'; echo; echo '## Plain heading'; echo; echo '<div id="div-anchor">Div</div>'; } > anchors.md
    printf '# Second\n\nSECOND_FILE_TOP\n\n<a id="target"></a>\n\nTarget\n' > second.md
  2. Open anchors.md in the thread file preview (workspace file, thread storage file and host file preview behave the same).
  3. Click "HTML anchor", "Heading", "Div".
  4. Click "Other file".

Also tried: a Cyrillic heading and a Cyrillic <a id> (#%D0%B1… in href), and #user-content-block-1. Same result.

Expected vs actual

Link                  href / target           Actual                                         Target in DOM
#block-1 (<a id>)     #block-1, _blank        new tab …/threads/thr_…#block-1, no scroll     no: empty <span> without id
#plain-heading        #plain-heading, _blank  new tab, no scroll                             <h2> without id
#div-anchor           #div-anchor, _blank     new tab, no scroll                             div#user-content-div-anchor
second.md#target      file:///…/second.md     second.md opens at the top, fragment dropped   yes, no scroll

Original tab survives, history.length 2 -> 2, click event defaultPrevented: false.

Expected: #… links stay in the preview and scroll the preview container to the matching element. file.md#x opens the file at x.

Evidence

Cause, layer by layer (observed in DOM and click events, code at main 3a2c49a):

  1. MarkdownAnchor sets target="_blank" on every link (L730). In handleAnchorClick a #… href matches no branch: resolveUrlOpenTarget returns unhandled for anything that is not http(s):// (L21-L33), so preventDefault is never called and the browser follows target=_blank.
  2. rehype-sanitize with the default schema prefixes raw HTML ids with user-content- (div#user-content-div-anchor). The sanitizer keeps the anchor.
  3. <a id="block-1"> has no href, so MarkdownAnchor returns <span>{children}</span> and drops the id (L687).
  4. Headings get no ids (no slug plugin), so GitHub-style heading links have no target.
  5. The document scrolls inside [data-file-preview-scroll-container], not the window, so native fragment navigation would not move it even with a live target.
  6. Local file routing builds file:///…/second.md without the fragment.

What you ruled out

Suggested priority and effort

Medium: every in-page link in a Markdown file preview (tables of contents, footnote-style references) opens a second copy of bb. Workaround: browser find or the Raw tab. No data loss. Effort Low for layers 1, 3, 4. A fix for those follows in a PR. file.md#x (layer 6) is not covered there.

Checks

  • I reproduced this on the latest release or on main, or I say above that I could not.
  • I searched open and closed issues for the same problem.
  • If an agent wrote this, the body ends with > AGENT GENERATED and links the thread or report. The investigation report lives in a private ops repo, the steps above are self-contained.

AGENT GENERATED

Activity

  1. added theissue type on Oct 25, 2026
  2. added
    ui
    partial-repro
    on Oct 25, 2026
  3. bb-slop-cop commented on Oct 25, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Classification: Bug · Priority: Medium · Effort: Medium · area: ui.

    Reproduction and root-cause report: PARTIALLY REPRODUCED · root-cause confidence: high · reproduction label: partial-repro.

    Four focused renderer regressions fail on trusted main in both clean checkouts: fragment clicks remain uncanceled with a new-tab target, HTML anchor IDs disappear, headings lack destination IDs, and relative file fragments are discarded. The application build and 117 existing tests pass. Chromium is unavailable, so actual new-tab behavior and preview scrolling remain unverified.

    No PR: Complete cross-file navigation needs an extension to the public file-location contract, outside the simple-fix safety rules.

    AGENT GENERATED

  4. lanjak commented on Nov 17, 2026

    @lanjak
    Contributor

    Footnote references still do not scroll in Markdown file previews

    #6756 fixed in-page #fragment links for headings and raw HTML ids. Footnote references are still broken: a click on [1] in a Markdown file preview does nothing. The back-reference link from the footnote works.

    Tested on: main at 1320c88e8a, Linux 7.3.4, Node 26.13.1. Tested with a component test that renders the real FilePreview with buildMarkdownFileRouting in jsdom and clicks both links. Not checked in a live browser.

    Steps

    1. Open a Markdown file with this content in a file preview:
      Text with a note[^1].
      
      [^1]: The note.
    2. Click the 1 reference.
    3. Click the back-reference arrow in the footnote.

    Observed

    content            element ids in the preview                                     scrollIntoView calls
    plain Markdown     A#user-content-fnref-1, H2#footnote-label                      A#user-content-fnref-1
    with <kbd>Ctrl</kbd>  A#user-content-user-content-fnref-1, H2#user-content-footnote-label   A#user-content-user-content-fnref-1
    

    The footnote <li> has no id, so the reference click (href #user-content-fn-1) finds no target. Only the back-reference scrolls.

    Cause

    1. MarkdownListItem renders <li> with className and children only. It drops the id that remark-gfm puts on each footnote item (markdown-preview.tsx#L1042-L1044). Keep Markdown footnote links inside the preview #3586 found the same gap and forwarded the id, but that PR was closed as stale.
    2. A second, latent issue: when the content contains raw HTML, the sanitized path (markdown-html.tsx#L11-L80) adds user-content- to footnote ids that remark-rehype already prefixed. The result is user-content-user-content-fn-1. findMarkdownFragmentElement also tries the id with one extra user-content- prefix (markdown-link-target.ts#L135-L148). Thus the lookup still finds the target. The ids differ between the two paths, and any other consumer of the ids sees the double prefix.

    Fix options

    Option Change Effect Risk
    A Forward id in MarkdownListItem Reference clicks scroll on both paths. Verified with the component test above: the click scrolls to LI#user-content-fn-1 (plain) and LI#user-content-user-content-fn-1 (HTML). Low. One line.
    B Pass remarkRehypeOptions={{ clobberPrefix: "" }} on the sanitized path only rehype-sanitize then adds the prefix once, so the HTML path gets single-prefixed ids. Hrefs become #fn-1, which the lookup resolves through its existing prefix fallback. Checked by a render of the HTML path: id="user-content-fn-1", href="#fn-1". Low to medium. Footnote hrefs differ between the two paths. Needs a test for both paths.
    C Set clobberPrefix: "" in the sanitize schema Removes the double prefix. Not recommended. Raw HTML ids from agent output are no longer prefixed, which removes the DOM-clobbering protection of rehype-sanitize.
    D Leave the double prefix The lookup fallback already covers it. Ids stay inconsistent between the two paths.

    Recommendation: A now, because it fixes the visible defect with one line. B is optional cleanup if consistent ids matter. Do not use C.

    This does not change timeline messages. Since #6756, #fragment links in messages render as plain text.

    AGENT GENERATED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    partial-reproui

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions