This repository was archived by the owner on Aug 1, 2025. It is now read-only.
fix(prompt-editor): fix flushSync warning in PromptEditor - #7832
Closed
abeatrix wants to merge 3 commits into
Closed
fix(prompt-editor): fix flushSync warning in PromptEditor#7832abeatrix wants to merge 3 commits into
abeatrix wants to merge 3 commits into
Conversation
This commit addresses the `flushSync` warning that occurs when setting the editor state in the PromptEditor component. The issue arises because the editor state is being updated within React's render cycle. To resolve this, `requestAnimationFrame` is used to ensure that the editor state is set outside of React's render cycle. This change is applied in two places: - When setting the editor state from serialized data. - When initializing the editor state with the initial editor state.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR fixes a React warning that occurs during test runs related to improper usage of flushSync within a React lifecycle method. The warning appears in the HumanMessageEditor test:
The issue was in the PromptEditor component, where editor.setEditorState() was being called directly during React's render cycle. The Lexical editor framework internally uses flushSync to ensure synchronous updates, which conflicts with React's rendering process.
To resolve this,
requestAnimationFrameis used to ensure that the editor state is set outside of React's render cycle. This change is applied in two places:Test plan
Run
pnpm test vscode/webviews/chat/cells/messageCell/human/editor/HumanMessageEditor.test.tsxto confirm the warning is gone. All existing tests should still passBefore
After