fix(desktop): prevent composer draft leak on new session - #62586
Open
pushpitkamboj wants to merge 2 commits into
Open
fix(desktop): prevent composer draft leak on new session#62586pushpitkamboj wants to merge 2 commits into
pushpitkamboj wants to merge 2 commits into
Conversation
teknium1
reviewed
Jul 11, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the focused Desktop fix. Current main still performs the draft restore in a passive effect at apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts:287-301, so moving this particular DOM restore to useLayoutEffect is aligned with the reported pre-paint flash.
Problems
apps/desktop/src/app/chat/composer/hooks/use-composer-draft.test.tsx:86checks afterflushSyncreturns. That establishes the eventual swap, but does not demonstrate that a passiveuseEffectcannot paint the old draft first.- #62490 also reports an initial Enter failure. The real Enter branch is
apps/desktop/src/app/chat/composer/index.tsx:558-589; the added hook-only test does not exercise that path.
Suggested changes
- Add a deterministic pre-paint regression test (or focused Electron/browser coverage) that fails under
useEffect. - If this PR is intended to close all of #62490, add a session-switch plus real-Enter integration regression.
Automated hermes-sweeper review.
|
|
||
| it('loads the new-session draft before paint when leaving an existing session', () => { | ||
| stashSessionDraft('session-a', 'previous draft', []) | ||
|
|
Contributor
There was a problem hiding this comment.
This assertion observes the editor only after flushSync returns, so it proves the eventual swap but not that the previous draft could not be painted first. Please add deterministic pre-paint coverage (or a focused Electron/browser regression) that fails with useEffect.
19 tasks
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.
What does this PR do?
Fixes a Desktop composer regression where a draft from the previously opened session could briefly appear in a newly created session.
The composer draft swap was running in a passive
useEffect, so React could paint the new-session view before the composer restored the__new__draft. This allowed the previous session's contentEditable text to appear in the new session for a frame and could make the first Enter feel ignored while the composer state was still catching up.This PR moves the per-session draft swap to
useLayoutEffect, which stashes the outgoing draft and loads the incoming draft before paint.Related Issue
Fixes #62490
Type of Change
Changes Made
apps/desktop/src/app/chat/composer/hooks/use-composer-draft.tsuseEffecttouseLayoutEffect.apps/desktop/src/app/chat/composer/hooks/use-composer-draft.test.tsxHow to Test
Automated checks run: