Skip to content

Search highlights (<mark>) cleared within milliseconds, invisible to users #14047

Description

@cderv

When navigating to a page via search (with ?q= parameter), the highlight() function adds <mark> elements around matching text. These marks are then cleared almost immediately (~24ms on quarto.org) by quarto-hrChanged events, making them invisible to users.

Steps to Reproduce

  1. Go to any Quarto website page with ?q=someterm (e.g. html-basics.html?q=format)
  2. Observe that no highlighted text is visible

Instrumented testing on quarto.org shows marks appear and disappear within a single frame:

404ms: 17 <mark> elements added by highlight()
428ms: 0 <mark> elements — all cleared by resetHighlighting()

Root Cause

The clearing chain:

  1. quarto-search.js registers a one-shot listener for quarto-hrChanged that calls clearHighlight():
    https://github.com/quarto-dev/quarto-cli/blob/aaaba63c2/src/resources/projects/website/search/quarto-search.js#L67-L76

  2. quarto-nav.js dispatches quarto-hrChanged from updateDocumentOffset():
    https://github.com/quarto-dev/quarto-cli/blob/aaaba63c2/src/resources/projects/website/navigation/quarto-nav.js#L196-L197

  3. updateDocumentOffset() is triggered during initial layout settling by a ResizeObserver on the header element and a setTimeout(250):
    https://github.com/quarto-dev/quarto-cli/blob/aaaba63c2/src/resources/projects/website/navigation/quarto-nav.js#L254-L269

The comment says "Clear search highlighting when the user scrolls sufficiently", but the event fires from layout recalculation, not user interaction.

Context

PR #14003 added text fragments (:~:text=) to search result URLs, which provides browser-native scroll-to-text highlighting that persists independently. This effectively works around the broken <mark> behavior for visible text, but text fragments cannot highlight content inside hidden elements (e.g. inactive Bootstrap tab panes).

Possible Fix

Delay the quarto-hrChanged/quarto-sectionChanged listener registration to skip initial layout settling events, or gate the clearing on actual user interaction (scroll, click).

Activity

  1. mcanouil commented on Feb 17, 2026

    @mcanouil
    Collaborator
  2. added
    enhancement
    on Feb 17, 2026
  3. cscheid commented on Feb 17, 2026

    @cscheid
    Member

    Between now and release, can we mark all "default" issues to 1.10?

  4. added this to the v1.10 milestone on Feb 17, 2026
  5. added 2 commits that reference this issue on Feb 17, 2026
    8812d82
    9519449
  6. cderv commented on Feb 18, 2026

    @cderv
    MemberAuthor

    While investigating this fix, I tested the interaction between JS <mark> highlights (?q=) and browser text fragments (:~:text=, added in #14003), building on observations from #13123.

    The two mechanisms serve different purposes:

    On fuse.js sites, they conflict: highlight() wraps text in <mark> tags, and this DOM mutation destroys the browser's text fragment highlight. Even with replaceState() blocked, the DOM mutation alone kills the text fragment. replaceState() then also strips :~:text= from the URL as collateral (since new URL(window.location) can't see text fragments).

    On Algolia sites (e.g. quarto.org), there's no conflict because ?q= is only added by fuseSearch(), not the Algolia path — though this is a configuration gap rather than a fundamental difference (#13123).

    The fix in #14049 addresses the <mark> clearing. The text fragment conflict is a separate pre-existing interaction.

  7. vezwork commented on Feb 19, 2026

    @vezwork
    Member

    See #9802

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

    enhancementsearch

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions