Repository navigation
[lexical] Bug Fix: use devInvariant for update recursion guard to avoid reporting a recovered condition as an uncaught error - #8631
Merged
Conversation
potatowagon
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7 and
zurfyx
as code owners
June 4, 2026 08:25
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…lluting prod fatals
potatowagon
force-pushed
the
navi/fix/recursion-guard-dev-invariant
branch
from
June 4, 2026 08:29
8dbdcc7 to
1e97e42
Compare
Collaborator
|
Why not run the test twice, once with devInvariant mocked to throw and once mocked to warn? |
etrepum
approved these changes
Jun 4, 2026
etrepum
left a comment
Collaborator
There was a problem hiding this comment.
I think the test could be better, we should know what happens when devInvariant doesn't throw here. The tests only check when it does. Fine to merge in the meantime though.
Contributor
Author
thanks @etrepum ! ill fix it in a followup PR |
This was referenced Jun 4, 2026
Merged
Merged
This branch was successfully deployed
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.
Description
#8542 added a guard in
$triggerEnqueuedUpdatesthat detects when update listeners endlessly enqueue more updates (infinite recursion). The guard breaks the cascade by clearing the update queue, then signaled the condition by throwing aninvariantinside atry/catchand routing the error toeditor._onError.The problem:
editor._onErrordefaults toconsole.error(and in many products is wired to error reporting). Because the recursion guard is a recoverable, self-healing internal condition — the cascade is already broken before it signals — routing it through_onErrorreports an already-handled, non-fatal event as an uncaught error.This mirrors #8617, which downgraded the
$assumeActiveEditorprecondition frominvarianttodevInvariantfor the same reason: throw loudly in development, warn quietly in production.What changed
packages/lexical/src/LexicalUpdates.ts: the recursion guard now signals viadevInvariantinstead ofinvariant+try/catch+editor._onError.console.warnonly — no longer surfaces as an uncaught error via_onError._cascadeCountreset) before the signal, so recursion is stopped in both builds. The namespace is preserved in the message (%sinterpolation) for attribution.packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx: updated the "Detects infinite recursivity on update listeners" test. SincedevInvariantno longer routes through_onError, the test now captures the unhandled error surfaced from the scheduled microtask, asserts the message + namespace, confirms_onErroris not invoked, and that the editor recovers after the cascade is cut.Reproduction
We attempted to construct a minimal repro of the underlying infinite-update loop (the condition #8542 guards against) but were not able to consistently reproduce it. Notes on why it is hard to trigger:
Given the difficulty of a deterministic repro, this PR focuses on the severity downgrade so that this recoverable condition no longer reports as an uncaught error in production, while remaining loud in development.
Test plan
pnpm test-unit packages/lexical/src/__tests__/unit/LexicalEditor.test.tsx— all 79 tests pass, including the updated recursion test.