fix(prompt-editor): fix flushSync warning in PromptEditor #7832
+27
−4
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,
requestAnimationFrame
is 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.tsx
to confirm the warning is gone. All existing tests should still passBefore
After