Skip to content

Conversation

@Soxasora
Copy link
Member

@Soxasora Soxasora commented Oct 14, 2025

Description

Fixes #2600
Adds the language dependency to the useEffect that dynamically loads the highlighter, triggering a reload of the highlighter once language is available.
Also memoizes the language computation and persists the loadHighlighter function across re-renders to avoid extra work.

Screenshots

Screen.Recording.2025-10-14.at.17.33.28.mp4

Additional Context

n/a

Checklist

Are your changes backward compatible? Please answer below:

For example, a change is not backward compatible if you removed a GraphQL field or dropped a database column.
Yes

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
8, it works correctly on the given text.

For frontend changes: Tested on mobile, light and dark mode? Please answer below:
n/a

Did you introduce any new environment variables? If so, call them out explicitly here:
n/a

Did you use AI for this? If so, how much did it assist you?
No


Note

Reloads the syntax highlighter when language becomes available/changes, memoizes language, and adds safe cleanup to avoid setting state after unmount.

  • Code rendering (components/text.js > Code):
    • Memoizes language from className via useMemo and updates loadHighlighter dependency to [className].
    • Updates useEffect dependencies to [inline, language, loadHighlighter]; early-returns for inline and math.
    • Adds abort/cleanup guard to prevent state updates after unmount while loading highlighter.
    • Minor refactor: uses loaded Highlighter and sets theme once loaded.

Written by Cursor Bugbot for commit ceabd84. This will update automatically on new commits. Configure here.

- add language to list of deps, to trigger a re-render once available
- persist highlighter loader in a ref, to avoid unnecessary rerenders
- memoize language computation from className
@Soxasora Soxasora marked this pull request as ready for review October 14, 2025 15:36
cursor[bot]

This comment was marked as outdated.

…t caching; stabilize CodeSkeleton

- import caching is not needed as dynamic from nextjs already does that
- CodeSkeleton depends on changing props, they're now part of the callback dependencies
cursor[bot]

This comment was marked as outdated.

@ekzyis ekzyis added the bug label Oct 19, 2025
@huumn huumn merged commit 626c5b6 into master Oct 28, 2025
7 checks passed
@huumn huumn deleted the fix_highlighter_deps branch October 28, 2025 01:21
Copy link

@adlai adlai left a comment

Choose a reason for hiding this comment

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

thank you @Soxasora for fixing and explaining the logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code blocks render differently within same post

5 participants