Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Feb 9, 2026

Fixes deep-linking to doc sub-sections (anchor links like #commands).

Problem

Docusaurus's built-in scroll handler skips hash-based scrolling on initial page load because previousLocation is null. It assumes the browser handles native hash scrolling, but React hydration resets the scroll position before the browser finishes its native anchor scroll. This means URLs like docs.roocode.com/roo-code-cloud/environments#commands land at the top of the page instead of the targeted section.

Solution

Added a Docusaurus clientModule (src/clientModules/scrollToAnchor.ts) that explicitly scrolls to the hash target after hydration settles:

  • Only runs on initial page load (when previousLocation is null) so it does not duplicate the core router's behavior for subsequent navigations
  • Uses requestAnimationFrame to wait for the DOM to settle after hydration
  • Falls back to a retry after 150ms for lazily-rendered content
  • Uses scrollIntoView() which respects the scroll-margin-top already set by Docusaurus's anchorTargetStickyNavbar class

Changes

  • src/clientModules/scrollToAnchor.ts -- new client module
  • docusaurus.config.ts -- registers the client module via clientModules

Verification

  • pnpm build passes
  • pnpm run check-types passes
  • pnpm run lint passes
  • Client module confirmed present in built JS bundle

View task on Roo Code Cloud


Important

Fixes initial page load hash-based scrolling in Docusaurus by adding a client module to handle scrolling after React hydration.

  • Behavior:
    • Fixes hash-based scrolling on initial page load by adding scrollToAnchorModule in src/clientModules/scrollToAnchor.ts.
    • Uses requestAnimationFrame and a 150ms retry to ensure scrolling after React hydration.
    • Only activates when previousLocation is null to avoid interfering with subsequent navigations.
  • Configuration:
    • Registers scrollToAnchorModule in docusaurus.config.ts under clientModules.

This description was created by Ellipsis for 6725136. You can customize this summary. It will automatically update as commits are pushed.

Docusaurus skips hash-based scrolling on initial page load because
previousLocation is null. It relies on the browser to handle it
natively, but React hydration resets the scroll position before
the browser finishes its native anchor scroll.

Add a clientModule that explicitly scrolls to the hash target after
hydration settles, filling the gap left by the core router.

Closes CLO-805
@vercel
Copy link

vercel bot commented Feb 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
roo-code-docs Ready Ready Preview, Comment Feb 9, 2026 1:52pm

Request Review

@roomote
Copy link
Contributor Author

roomote bot commented Feb 9, 2026

Rooviewer Clock   See task

Reviewed the anchor scrolling fix. One minor defensive-coding issue found:

  • decodeURIComponent in scrollToAnchor.ts can throw URIError on malformed hashes -- wrap in try-catch

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

Comment on lines +25 to +28
const id = decodeURIComponent(hash.substring(1));
if (!id) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decodeURIComponent throws a URIError when the hash contains a malformed percent-encoded sequence (e.g. #%ZZ). If someone shares or bookmarks such a URL, the unhandled exception would crash this callback and could prevent other client module hooks from running. Wrapping it in a try-catch keeps things defensive.

Suggested change
const id = decodeURIComponent(hash.substring(1));
if (!id) {
return;
}
let id: string;
try {
id = decodeURIComponent(hash.substring(1));
} catch {
return;
}
if (!id) {
return;
}

Fix it with Roo Code or mention @roomote and request a fix.

@mrubens mrubens marked this pull request as ready for review February 9, 2026 15:06
@mrubens mrubens merged commit f02d6d4 into main Feb 9, 2026
4 checks passed
@mrubens mrubens deleted the feature/CLO-805-fix-deep-linking-anchor-scrolling branch February 9, 2026 15:07
@roomote
Copy link
Contributor Author

roomote bot commented Feb 9, 2026

Rooviewer Clock   See task

Reviewed the anchor scrolling fix. Implementation correctly uses the ClientModule interface, properly gates on initial page load, and the requestAnimationFrame + retry strategy is sound. No new issues found beyond the prior review.

  • decodeURIComponent in scrollToAnchor.ts can throw URIError on malformed hashes -- wrap in try-catch (flagged in prior review)

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants