mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: Flush pending DOM updates before .focus() (#8901)
This commit is contained in:
parent
b5652b8e36
commit
8a1152ce36
1 changed files with 17 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import { flushSync } from "react-dom";
|
||||||
import { t } from "../i18n";
|
import { t } from "../i18n";
|
||||||
import type { DialogProps } from "./Dialog";
|
import type { DialogProps } from "./Dialog";
|
||||||
import { Dialog } from "./Dialog";
|
import { Dialog } from "./Dialog";
|
||||||
|
@ -43,7 +44,14 @@ const ConfirmDialog = (props: Props) => {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setAppState({ openMenu: null });
|
setAppState({ openMenu: null });
|
||||||
setIsLibraryMenuOpen(false);
|
setIsLibraryMenuOpen(false);
|
||||||
onCancel();
|
// flush any pending updates synchronously,
|
||||||
|
// otherwise it could lead to crash in some chromium versions (131.0.6778.86),
|
||||||
|
// when `.focus` is invoked with container in some intermediate state
|
||||||
|
// (container seems mounted in DOM, but focus still causes a crash)
|
||||||
|
flushSync(() => {
|
||||||
|
onCancel();
|
||||||
|
});
|
||||||
|
|
||||||
container?.focus();
|
container?.focus();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
@ -52,7 +60,14 @@ const ConfirmDialog = (props: Props) => {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setAppState({ openMenu: null });
|
setAppState({ openMenu: null });
|
||||||
setIsLibraryMenuOpen(false);
|
setIsLibraryMenuOpen(false);
|
||||||
onConfirm();
|
// flush any pending updates synchronously,
|
||||||
|
// otherwise it leads to crash in some chromium versions (131.0.6778.86),
|
||||||
|
// when `.focus` is invoked with container in some intermediate state
|
||||||
|
// (container seems mounted in DOM, but focus still causes a crash)
|
||||||
|
flushSync(() => {
|
||||||
|
onConfirm();
|
||||||
|
});
|
||||||
|
|
||||||
container?.focus();
|
container?.focus();
|
||||||
}}
|
}}
|
||||||
actionType="danger"
|
actionType="danger"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue