Skip to content
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
mainfrom
bee/fix-flushSync
Closed

fix(prompt-editor): fix flushSync warning in PromptEditor#7832
abeatrix wants to merge 3 commits into
mainfrom
bee/fix-flushSync

Conversation

@abeatrix

Copy link
Copy Markdown
Contributor

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:

  • When setting the editor state from serialized data.
  • When initializing the editor state with the initial editor state.

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 pass

Before

image

After

image

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.
@abeatrix
abeatrix requested a review from a team April 30, 2025 23:09
@abeatrix
abeatrix marked this pull request as draft May 1, 2025 04:26
@abeatrix
abeatrix removed the request for review from a team May 1, 2025 04:26
@abeatrix abeatrix closed this Jul 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant