fix: prevent stale navbar height cache causing scroll-spy URL mismatch on direct page load#438
Draft
fix: prevent stale navbar height cache causing scroll-spy URL mismatch on direct page load#438
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…avbar height Agent-Logs-Url: https://github.com/rohit-gohri/redocusaurus/sessions/6bf18279-8175-4771-8afe-4e07d35ecc45 Co-authored-by: rohit-gohri <31949290+rohit-gohri@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix URL updates after page refresh for examples
fix: prevent stale navbar height cache causing scroll-spy URL mismatch on direct page load
Mar 30, 2026
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.
On direct page load/refresh, clicking a sidebar item correctly scrolls the content but sets the URL to the previous menu entry instead of the clicked one. SPA navigation is unaffected.
Root cause
Redoc's
normalizeScrollYOffsetcaptures the navbar height once atAppStoreconstruction time when given a CSS selector string:On direct load, Docusaurus's
useIsBrowser()startsfalsethen flips totrue, triggering a secondAppStorecreation inside auseMemoduring React's render phase — before the current render is committed. At that momentgetBoundingClientRect()may return pre-commit navbar dimensions, so the cachedscrollYOffsetis wrong. The scroll-spy then resolves against the wrong threshold and activates item N-1 instead of N. SPA navigation always enters withisBrowser = true, so only one store is ever created, bypassing the window.Fix
In
useSpecOptions.ts, convert CSS selector strings to a dynamic function on the client instead of forwarding the raw string to Redoc. The function is invoked on every scroll event, reading the current navbar height from the DOM each time:0(no DOM).defaultOptions.scrollYOffsetinredocData.tsremains'nav.navbar'(must be JSON-serialisable plugin data).Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
redocly.github.io/opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/redocusaurus/redocusaurus/node_modules/@docusaurus/core/bin/docusaurus.mjs build git conf�� ect\|window\|document edocusaurus/packages/redocusaurus/src/plugin.ts p/bin/bash commit.gpgsign(dns block)If you need me to access, download, or install something from one of these locations, you can either: