Skip to content

Commit 4cbaad4

Browse files
Fix reset-or-adjust-state Effect in callout Heading
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9882eb3 commit 4cbaad4

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎packages/editor/src/widgets/callout.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,14 @@ function Heading(
228228
});
229229
}, [editor, callout.key]);
230230

231-
useEffect(() => {
232-
if (disabled) setChoosing(false);
233-
}, [disabled]);
231+
// Becoming disabled must close the picker immediately, not on the next
232+
// render pass — derive it during render instead of adjusting state in an
233+
// Effect after the fact.
234+
let disabledForRender = useRef(disabled);
235+
if (disabledForRender.current !== disabled) {
236+
disabledForRender.current = disabled;
237+
if (disabled && choosing) setChoosing(false);
238+
}
234239

235240
let choose = (value: string) => {
236241
if (disabledRef.current) return;

0 commit comments

Comments
 (0)