diff --git a/packages/ui/src/components/chat/composer/editor/ComposerEditor.tsx b/packages/ui/src/components/chat/composer/editor/ComposerEditor.tsx index 41a2825f..c248a53f 100644 --- a/packages/ui/src/components/chat/composer/editor/ComposerEditor.tsx +++ b/packages/ui/src/components/chat/composer/editor/ComposerEditor.tsx @@ -344,6 +344,10 @@ export const ComposerEditor = React.forwardRef { + const start = composerEditorSource.indexOf('// Controlled value:'); + expect(start).toBeGreaterThan(-1); + const end = composerEditorSource.indexOf('}, [value]);', start); + expect(end).toBeGreaterThan(start); + return composerEditorSource.slice(start, end); +}; + +describe('composer value writeback composition guard (issue #2527)', () => { + test('checks equality, then composition, before dispatching', () => { + const effect = writebackEffect(); + const equalityCheck = effect.indexOf('if (current === value) return;'); + const compositionGuard = effect.indexOf('if (view.compositionStarted) return;'); + const dispatch = effect.indexOf('view.dispatch({'); + + expect(equalityCheck).toBeGreaterThan(-1); + expect(compositionGuard).toBeGreaterThan(equalityCheck); + expect(dispatch).toBeGreaterThan(compositionGuard); + }); +});