Skip to content

[docs] Query heading for ToC on demand - #29204

Merged
eps1lon merged 1 commit into
mui:masterfrom
eps1lon:docs/toc-node-ondemand
Oct 27, 2021
Merged

eps1lon merged 1 commit into
mui:masterfrom
eps1lon:docs/toc-node-ondemand

Conversation

@eps1lon

@eps1lon eps1lon commented Oct 21, 2021 •

Copy link
Copy Markdown
Member

The responsible code for handling the "current marker" for the table of contents was always a bit sketchy since it relied on the headings of its items being available on commit. But that isn't necessarily true in a world where streaming rendering and selective hydration exists.

And it's also problematic in case the nodes for the heading itself get thrown away (preventing garbage collection).

Instead, we can just query the nodes on demand. This doesn't affect performance as far as I can tell. I profiled scroll performance with this change and we only spent <1ms in findActiveIndex with this change.

Preview https://deploy-preview-29204--material-ui.netlify.app/components/checkboxes/

@eps1lon eps1lon added the docs Improvements or additions to the documentation. label Oct 21, 2021
@eps1lon eps1lon added this to the React 18 milestone Oct 21, 2021
@mui-pr-bot

mui-pr-bot commented Oct 21, 2021 •

Copy link
Copy Markdown

No bundle size changes

Generated by 🚫 dangerJS against 8e9627d

@eps1lon
eps1lon marked this pull request as ready for review October 21, 2021 12:38
@eps1lon
eps1lon merged commit 6b12d46 into mui:master Oct 27, 2021
@eps1lon
eps1lon deleted the docs/toc-node-ondemand branch October 27, 2021 15:32
@oliviertassinari

Copy link
Copy Markdown
Member

It looks great

oliviertassinari added a commit to oliviertassinari/material-ui that referenced this pull request Oct 31, 2021
oliviertassinari added a commit to oliviertassinari/material-ui that referenced this pull request Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to the documentation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants