Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Remove HTML parsing, instead sanitize and set dangerously #521

Draft
wants to merge 16 commits into
base: customThemeShiki
Choose a base branch
from

Conversation

AVGVSTVS96
Copy link
Owner

Parsing HTML to React elements is a performance bottleneck which slows down code block rendering. This change removes the parsing and instead sanitizes the HTML with DOMPurify, and sets it with dangerouslySetInnerHTML

Also, this HTML processing logic is moved from CodeHighlight to useShiki, this way the hook always returns sanitized HTML, and logic is centralized.

Copy link

codesandbox bot commented Jul 22, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Jul 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
astro-portfolio-site ❌ Failed (Inspect) Jan 22, 2025 1:36am

Copy link
Owner Author

AVGVSTVS96 commented Jul 22, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

AVGVSTVS96 and others added 2 commits July 27, 2024 21:34
Create a hook to highlight code using custom theme and a highlighter created with that custom theme
@AVGVSTVS96 AVGVSTVS96 force-pushed the customThemeShiki branch 4 times, most recently from 04272be to 482374e Compare September 1, 2024 01:54
@AVGVSTVS96 AVGVSTVS96 force-pushed the customThemeShiki branch 2 times, most recently from 69822e9 to df6a518 Compare October 7, 2024 03:54
AVGVSTVS96 and others added 4 commits January 21, 2025 20:33
Add optional debouncing when debouncMs is passed to hook
Set 150ms in CodeHighlight for testing
Parsing HTML to React elements is a performance bottleneck which slows down code block rendering. This change removes the parsing and instead sanitizes the HTML with DOMPurify, and sets it with `dangerouslySetInnerHTML`

Also, this HTML processing logic is moved from `CodeHighlight` to `useShiki`, this way the hook always returns sanitized HTML, and logic is centralized.
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.

1 participant