Repository navigation
Conversation
#focusContent() looked up the target with `#${query.id}`, which is not a
valid selector when the id starts with a digit. querySelector threw, and
on a fresh load or a link to another page the throw skipped doneEach.
Use [id="..."] like onNavigate() already does.
|
@0z5a is attempting to deploy a commit to the Docsify Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
sy-records
requested review from
a team and
sy-records
and
a balanced review from Copilot
November 19, 2026 09:30
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the numeric-ID focus lookup fix.
No open issues 🎉
What changed in this PR
Fixes Docsify’s focus lookup for ?id= targets that begin with a digit, addressing #2865 without changing heading slug generation.
Changes:
- Uses an attribute selector to prevent numeric-leading IDs from causing selector errors and interrupting navigation hooks.
- Adds end-to-end regression tests for navigation completion and focus on a numeric ID.
| File | Description |
|---|---|
test/e2e/anchor-scroll.test.js |
Adds coverage for doneEach completion, absence of page errors, and numeric-ID focus. |
src/core/event/index.js |
Changes the focus-target lookup from an ID selector to an attribute selector. |
Review effort: Balanced
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#focusContent()looks up the?id=target withdom.find(`#${query.id}`). When the id starts with a digit (?id=2-usage,?id=2024) that isn't a valid CSS selector, soquerySelectorthrows. On a link to another page, or when the page is opened with that URL, this happens inside the fetch callback beforedone(), sodoneEachdoesn't run for that page and plugins like zoom-image, external-script and search (search: 'auto') skip it.This changes the lookup to
[id="${query.id}"], the same formonNavigate()already uses for its heading lookup and the one #2021 used inscroll.jsfor #2019. #2021 and #2253 (which added#focusContent()) both first shipped in 5.0.0, so the #2019 case has thrown again since then, just from a different line.It doesn't change slugs.
## 2. Usagestill gets_2-usage(#1516), so a GitHub-style#2-usagelink still doesn't scroll to that heading; it just no longer throws. An element whose id really starts with a digit, like<h2 id="2024">, now gets focus like any other target.How I found it
Reading how
?id=targets are looked up, I noticed#focusContent()uses#${query.id}whileonNavigate()andscroll.jsuse[id=…], then confirmed in Chromium that a fresh load of#/guide?id=26throws on 5.1.0 anddoneEachdoesn't run. A live case is the Tainacan wiki (5.1.0): the link from https://wiki.tainacan.org/#/indexing-pdf to./settings-page.md#1-search-and-performancelogs'#1-search-and-performance' is not a valid selectorand the images on the settings page don't get zoom-image. Details are in the issue.Where this can show up in practice
Numbered headings with a hand-written table of contents (
[1. Overview](#1-overview)) are a common pattern in docs that are also read on GitHub, and pure-number anchors come from things like comment widgets (#2019). On those pages anydoneEachplugin is skipped after following such a link. Besides the Tainacan wiki I haven't seen a field report.Related issue, if any:
Fixes #2865
What kind of change does this PR introduce?
For any code change,
Does this PR introduce a breaking change?
Testing
test/e2e/anchor-scroll.test.js:guide.md#2-usage: ondevelopthe page error is theSyntaxErroranddoneEachonly ran for#/; with the change there are no page errors anddoneEachran for#/and#/guide?id=2-usage.[Jump to 2024](#2024)next to<h2 id="2024">: ondevelopthe heading never gets focus; with the change it does.developand pass with the change in Chromium, Firefox and WebKit (Playwright), and the two tests with--repeat-each=20pass 120/120 across the three engines. The existing anchor-scroll tests (?id=target-section) pass before and after.npm run lint,npm run test:unit(54),npm run test:integration(79) andnpx playwright test --project=chromium(107) pass.#/guide?id=26: 5.1.0dist/logs theSyntaxError,doneEachdoesn't run and the image isn't zoomable; with the builtdist/from this branch there is no error,doneEachruns,<p id="26">has focus and the image is zoomable. Control:#/guidewithout?idon 5.1.0 runsdoneEachand the image is zoomable.Platform: macOS
Tested in the following browsers: