Repository navigation
[lexical] Feature: add onWarn editor hook and route cascade guard through it - #8653
Closed
potatowagon wants to merge 2 commits into
Closed
potatowagon wants to merge 2 commits into
potatowagon wants to merge 2 commits into
Conversation
Add an optional `onWarn` hook to CreateEditorArgs that mirrors `onError` but at warning severity. The hook defaults to `console.warn`, preserving existing OSS behavior. The update-recursion guard in `$triggerEnqueuedUpdates` (cascade count > 99) now routes through `editor._onWarn` in production instead of a raw `console.warn` via `devInvariant`. In development (__DEV__), it still throws loudly via `devInvariant` for immediate developer feedback. This allows embedders to wire `onWarn` to their own telemetry systems (e.g. structured logging) without the warning being lost to the browser console. It complements #8631 which downgraded this from an error to a warning — this PR ensures the warning remains capturable. Why a separate hook rather than reusing `onError`: #8631 deliberately moved this off `_onError` because routing a recovered condition through the error handler (typically console.error) reported it as an uncaught error and prior history (#8596) showed it could freeze the editor.
potatowagon
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7 and
zurfyx
as code owners
June 8, 2026 14:14
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
reviewed
Jun 8, 2026
Contributor
Author
|
You're right — #8644 already covers this. Closing as duplicate. Sorry for the noise! |
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
Add an optional
onWarnhook toCreateEditorArgsthat mirrorsonErrorbut at warning severity. The hook defaults toconsole.warn, preserving existing OSS behavior.The update-recursion guard in
$triggerEnqueuedUpdates(cascade count > 99) now routes througheditor._onWarnin production instead of a rawconsole.warnviadevInvariant. In development (__DEV__), it still throws loudly viadevInvariantfor immediate developer feedback.This allows embedders to wire
onWarnto their own telemetry systems (e.g. structured logging) without the warning being lost to the browser console. It complements #8631 which downgraded this from an error to a warning — this PR ensures the warning remains capturable.Why a separate hook rather than reusing
onError#8631 deliberately moved this off
_onErrorbecause routing a recovered condition through the error handler (typicallyconsole.error) reported it as an uncaught error, and prior history (#8596) showed routing throughonErrorcould freeze the editor. A dedicatedonWarnkeeps the severity separation clean.Changes
LexicalEditor.ts: AddonWarn?: ErrorHandlertoCreateEditorArgs; add_onWarn: ErrorHandlerfield onLexicalEditorclass, defaulting toconsole.warn.LexicalUpdates.ts: In the_cascadeCount > 99branch of$triggerEnqueuedUpdates, calleditor._onWarn(new Error(...))in production; retaindevInvariantthrow in__DEV__.Closes: N/A (feature request from internal sync)
Test plan
Automated
tsc --noEmitpasses)Manual verification
onWarn: behavior identical to before (cascade guard logs toconsole.warn)onWarn: (err) => myLogger.warn(err): embedder receives the Error object for structured telemetry