Skip to content

Fix: avoid infinite transform loop in Shiki/Prism highlight toggle#8607

Closed
messiawrq-design wants to merge 1 commit into
facebook:mainfrom
messiawrq-design:main
Closed

Fix: avoid infinite transform loop in Shiki/Prism highlight toggle#8607
messiawrq-design wants to merge 1 commit into
facebook:mainfrom
messiawrq-design:main

Conversation

@messiawrq-design

Copy link
Copy Markdown

Description

Closes #8605

Fixes an issue where changing syntax highlighters (e.g. from Prism to Shiki) on a Code block inside the Playground causes an infinite transform error (errorOnInfiniteTransforms).
The root cause was that getIsSyntaxHighlightSupported() returns undefined initially or during switching phases when nodes are parsed, which made the ! negative condition evaluate to true, thus endlessly re-triggering $codeNodeTransform by calling setIsSyntaxHighlightSupported(true/false).

Implementation Details:

  • Updated CodeHighlighterPrism.ts to strictly check !== true / !== false before mutating isSyntaxHighlightSupported.
  • Applied identical strict conditional fixes to CodeHighlighterShiki.ts and FacadeShiki.ts.
  • Validated fixes locally passing pnpm build and pnpm test.

Bounty Payout Note:
If this contribution is eligible for an open-source bounty or reward program under Meta/Lexical initiatives, please route the bounty allocation to the following Solana address:
6sF8p22Gg83NKTJ6dvya7Srv4USCniZnP47DwQwK7Mtp

@meta-cla

meta-cla Bot commented Jun 1, 2026

Copy link
Copy Markdown

Hi @messiawrq-design!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 1, 2026 1:56am
lexical-playground Ready Ready Preview, Comment Jun 1, 2026 1:56am

Request Review

@messiawrq-design

Copy link
Copy Markdown
Author

I signed it!

@potatowagon

Copy link
Copy Markdown
Contributor

Review from potatowagon's AI reviewer:

Thanks for the fix! The logic here is correct — using strict inequality checks to avoid the infinite transform loop is the right approach.

However, I'd recommend looking at #8606 by @levensta which addresses the same infinite loop issue with a slightly cleaner approach (setting the unsupported flag only once). Between the two PRs:

Concerns with this PR:

  1. CLA not signed — the Facebook CLA check is failing, which blocks merge
  2. Extraneous code.patch file — appears to be accidentally committed
  3. Duplicate fix — [lexical-code-shiki] Bug Fix: Set the unsupported syntax flag only once #8606 solves the same problem and is further along in review

What I verified: The code logic is sound — the strict inequality checks prevent re-triggering transforms when the state is already set. No regressions to existing behavior.

Recommendation: Unless there's a reason to prefer this approach over #8606, I'd suggest the maintainers go with #8606 which doesn't have the CLA/cleanup issues.

@etrepum

etrepum commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

The solution in #8606 is better so this PR will be closed when that PR is merged

@etrepum etrepum closed this in #8606 Jun 1, 2026

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

Concern ⚠️ — CLA check is failing; code fix looks correct but the PR includes a stale patch file.

What this does: Fixes an infinite transform loop in the Shiki/Prism code highlighters. The bug: getIsSyntaxHighlightSupported() can return null (not just true/false), so !node.getIsSyntaxHighlightSupported() evaluates to true when the value is null, triggering setIsSyntaxHighlightSupported(true), which marks the node dirty, re-triggers the transform, and loops forever. The fix uses strict equality (!== true, !== false) to correctly handle the null/undefined initial state without triggering redundant mutations.

What I checked:

  • ✅ Logic correctness: Using strict inequality (!== true / !== false) correctly handles the three-state scenario (null | true | false) — only calls the setter when the value actually needs to change.
  • ✅ Applied consistently across all 3 files (CodeHighlighterPrism.ts, CodeHighlighterShiki.ts, FacadeShiki.ts).
  • ✅ www compat: No public API changes. Internal behavior fix only.

Issues:

  • CLA check failing — must be signed before merge.
  • ⚠️ Includes code.patch file — appears to be a stale patch file committed to the repo root. This should be removed before merge or moved to a documentation location.

Note: This PR overlaps with #8606 (same area, Shiki-only). If both land, there may be a merge conflict. #8606 takes a different approach (reordering the loadCodeLanguage call). The approaches are complementary — this PR's strict equality check is more defensive and covers both Prism and Shiki.

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

Labels

None yet

3 participants