Skip to content

EDU-16758: fix API reference hash navigation#1268

Merged
PedroAntunesCosta merged 4 commits into
mainfrom
fix/edu-16758-api-reference-hash-navigation
May 26, 2026
Merged

EDU-16758: fix API reference hash navigation#1268
PedroAntunesCosta merged 4 commits into
mainfrom
fix/edu-16758-api-reference-hash-navigation

Conversation

@PedroAntunesCosta
Copy link
Copy Markdown
Contributor

Summary

Fixes the API reference (/docs/api-reference/[slug]) navigation so the RapiDoc focused viewer stays in sync with the URL hash across deep links, sidebar clicks, and same-slug Next-Link transitions between endpoints.

Changes

  • src/pages/docs/api-reference/[slug].tsx
    • One syncHash effect mirrors window.location.hash (and the legacy ?endpoint= query) into clientHash state and forwards the new path to RapiDoc via rapidoc.current.scrollToPath(...).
    • The effect listens to hashchange plus the Next router hashChangeComplete and routeChangeComplete events, and re-runs when slug changes.
    • Removed the secondary scrollDoc and router.push(window.location.href) effects that fought with RapiDoc's internal handlers.
    • Added route-prefix="#" on the <rapi-doc> element so RapiDoc never auto-picks ?endpoint= as its router prefix on bare-slug loads.
    • Added a window.scrollTo({ top: 0 }) reset on overview→endpoint transitions.
    • Added extensive comments explaining the bug dynamics and why each piece is needed.
  • RapiDoc submodule pointer bumped to include the companion fix in getElementIDFromURL().

Why

The page renders two views per slug — overview (no hash, server-rendered, indexable) and endpoint (with hash, RapiDoc focused viewer). Before this change, deep links with a hash and same-API endpoint→endpoint navigation via the sidebar would render the API overview or the wrong endpoint. Two compounding causes:

  1. RapiDoc's routePrefix would default to ?endpoint= on bare-slug loads, so its getElementIDFromURL() returned the entire URL on every spec (re)load and the focused template fell back to the first endpoint.
  2. Next-Link sidebar clicks fire routeChangeComplete/hashChangeComplete but not the native hashchange, so neither the page nor RapiDoc's internal listener was re-syncing on those navigations.

Fix verified locally with Playwright across cold-loads (with/without hash), overview-table clicks, sidebar clicks (same API and across APIs), and Previous/Next pagination.

Related Task

EDU-16758

Companion PR

Depends on vtexdocs/RapiDoc#47 (submodule pointer in this PR is at the fix commit on the fork branch). Once that PR merges, the submodule pointer should be re-pinned to the merged commit on vtexdocs/RapiDoc:master.

@PedroAntunesCosta PedroAntunesCosta added bug Something isn't working release-patch Patch version bump labels May 19, 2026
@PedroAntunesCosta PedroAntunesCosta self-assigned this May 19, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 19, 2026

Deploy Preview for elated-hoover-5c29bf ready!

Name Link
🔨 Latest commit 180bf85
🔍 Latest deploy log https://app.netlify.com/projects/elated-hoover-5c29bf/deploys/6a15bcd70e37240009e7e603
😎 Deploy Preview https://deploy-preview-1268--elated-hoover-5c29bf.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

A total of 2 tests failed!

API guides documentation page

1 failing tests:

  • Check if the sidebar collapse button works (/docs/guides)

API reference documentation page

1 failing tests:

  • Check if the sidebar collapse button works (/docs/api-reference)

For more information, open the cypress action summary page.

@PedroAntunesCosta PedroAntunesCosta merged commit 5e3c9c5 into main May 26, 2026
6 of 7 checks passed
@PedroAntunesCosta PedroAntunesCosta deleted the fix/edu-16758-api-reference-hash-navigation branch May 26, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working release-patch Patch version bump

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants