Fix rendering issues when both chunking and React's strict mode are enabled#5988
Merged
dylans merged 1 commit intoianstormtaylor:mainfrom Dec 16, 2025
Merged
Conversation
🦋 Changeset detectedLatest commit: 32d56dd The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
12joan
commented
Dec 10, 2025
| 'chunk' | ||
| ), | ||
| showSelectedHeadings: parseBoolean('selected_headings', false), | ||
| strictMode: parseBoolean('strict', false), |
Contributor
Author
12joan
commented
Dec 10, 2025
Contributor
Author
There was a problem hiding this comment.
This file was changed as a result of yarn tsc:examples
dylans
approved these changes
Dec 16, 2025
This was referenced Dec 16, 2025
Merged
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
If React's strict mode and the experimental chunking optimisation are both enabled, this caused rendering issues inside chunks that prevented
slate-reactfrom synchronising changes to the editor value with the DOM. This PR resolves these issues by adjusting the timing of when the chunk tree'smodifiedChunksset is cleared.Example
Recording of the bug as reported by z2devil on Slack:
20251210170131.mp4
Context
The chunking optimisation works by iteratively mutating a nested "chunk tree" object as part of
useChildrenevery time the parent element renders. On each iteration, the new children array is "reconciled" with the chunk tree, analogous to how React reconciles the DOM with its virtual DOM. This reconciliation can result in chunks being added, removed or modified.Since each individual chunk in the chunk tree is mutable, React cannot automatically determine whether the component corresponding to each chunk needs to be re-rendered. For this reason, the chunk tree maintains a set of
modifiedChunks, which are chunks that have been modified since the last render. If a given chunk appears in this set, we bypass React's memoisation and re-render the chunk's component.Prior to this PR, this
modifiedChunksset was cleared at the start of each iteration (i.e. at the start of each render), so that the set included only those chunks that were modified as part of the current iteration. However, this caused issues with React's strict mode, in which each component's render function is called twice prior to that component actually being rendered.This meant that on the first render pass,
modifiedChunkswas correct but unused. On the second render pass (caused by strict mode),modifiedChunkshad already been cleared, and the chunk tree had already been updated. This meant thatmodifiedChunkwas empty whenReact.memochecked whether each chunk component needed to be re-rendered, resulting in the chunk component failing to update in response to changes to the editor value.This PR fixes this by only clearing
modifiedChunksinside auseEffect, by which time its value has already been used.Checks
yarn test.yarn lint. (Fix errors withyarn fix.)yarn start.)yarn changeset add.)