Skip to content

Conversation

@lakshya-byte
Copy link

@lakshya-byte lakshya-byte commented Jan 2, 2026

Description

Fixes #4845

  • Fixes an issue where the “On this page” (TOC) active highlight does not persist correctly when navigating between documentation pages.
  • Reinitializes the TOC/ScrollSpy behavior on route change, ensuring the correct section is highlighted after navigation.
  • Improves consistency and usability of the Docs reading experience.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where the Table of Contents did not properly refresh when navigating between different pages.

✏️ Tip: You can customize this high-level summary in your review settings.

@netlify
Copy link

netlify bot commented Jan 2, 2026

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 22921d1
🔍 Latest deploy log https://app.netlify.com/projects/asyncapi-website/deploys/6957fd88cb7aa60008f33010
😎 Deploy Preview https://deploy-preview-4854--asyncapi-website.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.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 2, 2026

📝 Walkthrough

Walkthrough

A React key prop is added to the TOC component in DocsLayout.tsx, set to router.asPath to force component remounting on route changes. This resolves stale react-scrollspy state during client-side navigation between documentation pages.

Changes

Cohort / File(s) Summary
TOC Component Key Fix
components/layout/DocsLayout.tsx
Added key={router.asPath} prop to TOC component to force remounting when the route path changes, resetting react-scrollspy listeners and active section tracking

Estimated Code Review Effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐰 A key's been placed upon the TOC,
When paths do change, it wakes from sleep,
Scrollspy listeners fresh and spry,
The highlight now will always keep!
No stale, forgotten state to weep.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and accurately describes the main change: reinitializing TOC on route changes to fix the highlighting bug.
Linked Issues check ✅ Passed The code change directly implements the proposed solution from issue #4845 by forcing TOC remount via key={router.asPath}, addressing the root cause.
Out of Scope Changes check ✅ Passed The modification is narrowly scoped to the DocsLayout component with only a single rendering attribute added; no extraneous changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@asyncapi-bot
Copy link
Contributor

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 39
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-4854--asyncapi-website.netlify.app/

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
components/layout/DocsLayout.tsx (1)

146-146: Consider using router.pathname instead of router.asPath for more targeted remounting.

While router.asPath works correctly, it includes query parameters and hash fragments, causing the TOC to remount even for hash-only navigation within the same page (e.g., clicking TOC links that only change #section1#section2). Since ScrollSpy tracks scroll position automatically, remounting on hash-only changes may be unnecessary.

Using router.pathname would limit remounts to actual page changes, reducing unnecessary reinitializations while still fixing the cross-page navigation bug.

🔎 Alternative implementation
-                  key={router.asPath}
+                  key={router.pathname}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 218a4dd and 22921d1.

📒 Files selected for processing (1)
  • components/layout/DocsLayout.tsx
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: sammy200-ui
Repo: asyncapi/website PR: 4804
File: components/navigation/Filter.tsx:32-41
Timestamp: 2025-12-29T14:21:43.887Z
Learning: In the Filter component (components/navigation/Filter.tsx), the useEffect hooks are intentionally designed to react only to route/URL changes, not to prop changes (data, checks, onFilter). The omitted dependencies are by design.
Learnt from: akshatnema
Repo: asyncapi/website PR: 3262
File: components/newsroom/FeaturedBlogPost.tsx:90-92
Timestamp: 2024-10-11T07:38:35.745Z
Learning: In Next.js, nested `<a>` tags cause hydration issues due to invalid HTML. To fix this, avoid nesting `<a>` tags by replacing inner `<a>` tags with non-interactive elements like `<span>`, and use click handlers to maintain interactivity if needed.
Learnt from: akshatnema
Repo: asyncapi/website PR: 3262
File: components/Avatar.tsx:35-44
Timestamp: 2024-10-11T10:46:58.882Z
Learning: In Next.js, when avoiding nested `<a>` tags due to hydration issues, use accessible non-link elements like `<button>` or `<span>` with appropriate roles, `tabIndex`, and event handlers to maintain accessibility and SEO.
Learnt from: akshatnema
Repo: asyncapi/website PR: 3262
File: components/navigation/BlogPostItem.tsx:95-119
Timestamp: 2024-10-11T11:32:30.226Z
Learning: In the `BlogPostItem` component (`components/navigation/BlogPostItem.tsx`), nesting `<a>` tags inside the parent `Link` component leads to hydration issues; therefore, we should avoid nesting `<a>` tags inside `Link` components in this component.
📚 Learning: 2025-12-29T14:21:43.887Z
Learnt from: sammy200-ui
Repo: asyncapi/website PR: 4804
File: components/navigation/Filter.tsx:32-41
Timestamp: 2025-12-29T14:21:43.887Z
Learning: In the Filter component (components/navigation/Filter.tsx), the useEffect hooks are intentionally designed to react only to route/URL changes, not to prop changes (data, checks, onFilter). The omitted dependencies are by design.

Applied to files:

  • components/layout/DocsLayout.tsx
📚 Learning: 2024-10-11T11:32:30.226Z
Learnt from: akshatnema
Repo: asyncapi/website PR: 3262
File: components/navigation/BlogPostItem.tsx:95-119
Timestamp: 2024-10-11T11:32:30.226Z
Learning: In the `BlogPostItem` component (`components/navigation/BlogPostItem.tsx`), nesting `<a>` tags inside the parent `Link` component leads to hydration issues; therefore, we should avoid nesting `<a>` tags inside `Link` components in this component.

Applied to files:

  • components/layout/DocsLayout.tsx
📚 Learning: 2024-10-11T10:46:58.882Z
Learnt from: akshatnema
Repo: asyncapi/website PR: 3262
File: components/Avatar.tsx:35-44
Timestamp: 2024-10-11T10:46:58.882Z
Learning: In Next.js, when avoiding nested `<a>` tags due to hydration issues, use accessible non-link elements like `<button>` or `<span>` with appropriate roles, `tabIndex`, and event handlers to maintain accessibility and SEO.

Applied to files:

  • components/layout/DocsLayout.tsx
📚 Learning: 2025-12-29T14:21:28.216Z
Learnt from: sammy200-ui
Repo: asyncapi/website PR: 4804
File: components/navigation/Filter.tsx:32-41
Timestamp: 2025-12-29T14:21:28.216Z
Learning: In the asyncapi/website repository, when you intentionally omit dependencies in React hooks (e.g., useEffect, useMemo), add an eslint-disable comment with an explanatory note above the line to justify the design choice. For example: // eslint-disable-next-line react-hooks/exhaustive-deps: intentionally omitting dependencies to avoid unnecessary re-runs. This helps reviewers understand the rationale and keeps lint guidance informative.

Applied to files:

  • components/layout/DocsLayout.tsx
🪛 GitHub Actions: PR testing - if Node project
components/layout/DocsLayout.tsx

[error] 146-146: Prettier: Replace ·=· with =

⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Redirect rules - asyncapi-website
  • GitHub Check: Header rules - asyncapi-website
  • GitHub Check: Pages changed - asyncapi-website
  • GitHub Check: Lighthouse CI


<div className={`xl:flex ${post.toc && post.toc.length ? 'xl:flex-row-reverse' : ''}`}>
<TOC
key = {router.asPath}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix formatting: Remove spaces around the equals sign.

The spacing violates Prettier rules and blocks the pipeline.

🔎 Proposed fix
-                  key = {router.asPath}
+                  key={router.asPath}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
key = {router.asPath}
key={router.asPath}
🧰 Tools
🪛 GitHub Actions: PR testing - if Node project

[error] 146-146: Prettier: Replace ·=· with =

🤖 Prompt for AI Agents
In components/layout/DocsLayout.tsx around line 146, the JSX prop assignment
"key = {router.asPath}" has extra spaces around the equals sign; remove the
spaces so it reads "key={router.asPath}" to satisfy Prettier and unblock the
pipeline.

@princerajpoot20
Copy link
Member

@lakshya-byte pipeline is failing. have a look on that. Also please make sure to attach testing evidence from the temporary netlify deployed link

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.

[Bug] TOC active section highlight breaks after navigating between pages

3 participants