Fix normalization performance and DOM error handling#2241
Draft
christianhg wants to merge 3 commits intomainfrom
Draft
Fix normalization performance and DOM error handling#2241christianhg wants to merge 3 commits intomainfrom
christianhg wants to merge 3 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 018a41b The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
When toSlatePoint is called with suppressThrow: true (e.g., from toSlateRange during selection change handling), internal findPath calls could still throw "Unable to find the path for Slate node" errors during component unmount when node references become stale. Wrap both findPath calls in try-catch blocks that return null when suppressThrow is enabled, matching the existing error handling pattern in the rest of the function. Based on upstream slate-dom PR #6004.
The useIsomorphicLayoutEffect that registers document-level focus/blur event listeners had an empty dependency array. The listener closure captures editor, so if the editor instance changes, the old closure becomes stale. Adding editor to the dependency array ensures the listeners are re-registered with the current editor instance. Based on upstream slate-react PR #6012.
e60f40b to
4d4987f
Compare
…hing 6x overall speedup, 24x in normalizeNode itself when pasting 10,000 lines. Key changes: - Split inline/block child handling into separate loops instead of a single loop with complex nested conditions - Refetch element after each transform operation (fixes stale reference bugs since Slate clones to new immutable references on mutation) - Moved children coercion earlier (before the main loop) - Replaced isEditor() check with direct reference comparison - Removed isLast variable in favor of direct length comparison Merged with our createSpan() calls (PR #2223) — uses editor.createSpan() instead of { text: '' } for schema-aware span creation in three places: empty element padding, inline-before padding, and inline-after padding. Based on upstream slate PR #5970.
4d4987f to
018a41b
Compare
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.
Three fixes:
1. Respect
suppressThrowintoSlatePointfindPath callsWhen
toSlatePointis called withsuppressThrow: true(e.g., fromtoSlateRangeduring selection change handling), internalfindPathcalls could still throw "Unable to find the path for Slate node" errors during component unmount when node references become stale. Wraps both calls in try-catch blocks that return null whensuppressThrowis enabled.2. Fix stale closure in focus/blur event listener
The
useIsomorphicLayoutEffectthat registers document-level focus/blur event listeners had an empty dependency array. The listener closure captureseditor, so if the editor instance changes, the old closure becomes stale. Addseditorto the dependency array.3. Optimize
normalizeNode(6x speedup)Full rewrite of
normalizeNodewith:isEditor()Merged with
editor.createSpan()from PR #2223 for schema-aware span creation.