fix: support mutations from child nodes for dynamic TOC#2363
Merged
Conversation
✅ Deploy Preview for rspress ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for rspress-v2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
f363a87 to
ed5121a
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the dynamic table of contents by detecting heading mutations within child nodes and refactors the mutation observer loops to for…of. It also adds required type definitions and an end-to-end fixture to verify dynamic updates.
- Refactor
useDynamicTocto detect added/removed heading nodes (including children) using labeledfor…ofloops. - Add
@types/webto support web types in the theme package. - Introduce a new E2E fixture (
dynamic-toc) with config, sample component, MDX doc, and Playwright test.
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/theme-default/src/components/Aside/useDynamicToc.ts | Refactored MutationObserver loops, unified added/removed handling, and child-node checks. |
| packages/theme-default/package.json | Added @types/web dependency for web-type definitions. |
| e2e/fixtures/dynamic-toc/rspress.config.ts | Added Rspress fixture config file. |
| e2e/fixtures/dynamic-toc/package.json | Added fixture package.json with dependencies. |
| e2e/fixtures/dynamic-toc/index.test.ts | Added Playwright test for dynamic TOC updates. |
| e2e/fixtures/dynamic-toc/doc/index.mdx | Sample MDX page using the Term component. |
| e2e/fixtures/dynamic-toc/components/Term.tsx | Sample React component that injects dynamic content. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)
packages/theme-default/src/components/Aside/useDynamicToc.ts:100
- [nitpick] The loop variable
nodesis ambiguous; consider renaming it tonodeListornodesCollectionfor clearer intent.
for (const nodes of [mutation.addedNodes, mutation.removedNodes]) {
e2e/fixtures/dynamic-toc/index.test.ts:22
- [nitpick] This test covers addition of headings but not removal. Consider adding a scenario where the component unmounts or headings are removed to verify the TOC updates correctly for
removedNodes.
test('Index page', async ({ page }) => {
SoonIter
approved these changes
Jul 10, 2025
Member
|
thanks❤ |
2 tasks
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.

Summary
support mutations from child nodes for dynamic TOC
also refactor to use
for ofto reduce loop executionRelated Issue
close #2346
Checklist