fix(ContentToc): correct highlight feature for custom depth headers#6282
fix(ContentToc): correct highlight feature for custom depth headers#6282
Conversation
Updated ContentToc component to scroll spy only the headers (links) passed in the props. Fixes issue nuxt#5967
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughReplaces two Nuxt lifecycle callbacks that queried the DOM for all Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/runtime/components/content/ContentToc.vue`:
- Around line 196-213: The page hook handlers register identical logic and can
throw when props.links is empty and leak when the component unmounts; refactor
by extracting the logic into a single handler function (e.g.,
computeHeadingsOrUpdate) that calls flattenLinks(props.links || []) and returns
early if the flattened array is empty (avoid calling document.querySelectorAll
with an empty selector), use CSS.escape when building the selector, register
that single handler for both "page:loading:end" and "page:transition:finish" via
nuxtApp.hooks.hook, store the returned unregister functions and call them in
onUnmounted to avoid leaks, and fix lint issues by using single quotes, removing
extra semicolons, and removing trailing commas to satisfy pnpm run lint;
reference functions/idents: nuxtApp.hooks.hook, flattenLinks, updateHeadings,
props.links, onUnmounted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8aa94222-067d-4aca-a8c4-8e83e70dacf9
📒 Files selected for processing (1)
src/runtime/components/content/ContentToc.vue
commit: |
benjamincanac
left a comment
There was a problem hiding this comment.
Would you mind putting back imports in their original order?
🔗 Linked issue
Resolves #5967
❓ Type of change
📚 Description
In the ContentToc component, the useScrollSpy was attached to
h2andh3headings independently of the links passed in the props or thecontent/build/markdown/toc/depthconfiguration entry of Nuxt Content.This caused the height of the indicator to be "wrong".
The fix was to instruct the spy to only look for the actual links passed in the props.
📝 Checklist