mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: scene not initialized properly when tab not focused (#2677)
Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
parent
0cf58adb4c
commit
aef3644c93
3 changed files with 20 additions and 16 deletions
|
@ -93,7 +93,6 @@ type Scene = ImportedDataState & { commitToHistory: boolean };
|
|||
const initializeScene = async (opts: {
|
||||
resetScene: ExcalidrawImperativeAPI["resetScene"];
|
||||
initializeSocketClient: CollabAPI["initializeSocketClient"];
|
||||
onLateInitialization?: (scene: Scene) => void;
|
||||
}): Promise<Scene | null> => {
|
||||
const searchParams = new URLSearchParams(window.location.search);
|
||||
const id = searchParams.get("id");
|
||||
|
@ -124,17 +123,15 @@ const initializeScene = async (opts: {
|
|||
} else {
|
||||
// https://github.com/excalidraw/excalidraw/issues/1919
|
||||
if (document.hidden) {
|
||||
window.addEventListener(
|
||||
"focus",
|
||||
() =>
|
||||
initializeScene(opts).then((_scene) => {
|
||||
opts?.onLateInitialization?.(_scene || scene);
|
||||
}),
|
||||
{
|
||||
once: true,
|
||||
},
|
||||
);
|
||||
return null;
|
||||
return new Promise((resolve, reject) => {
|
||||
window.addEventListener(
|
||||
"focus",
|
||||
() => initializeScene(opts).then(resolve).catch(reject),
|
||||
{
|
||||
once: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
isCollabScene = false;
|
||||
|
@ -222,9 +219,6 @@ function ExcalidrawWrapper(props: { collab: CollabAPI }) {
|
|||
initializeScene({
|
||||
resetScene: excalidrawApi.resetScene,
|
||||
initializeSocketClient: collab.initializeSocketClient,
|
||||
onLateInitialization: (scene) => {
|
||||
initialStatePromiseRef.current.promise.resolve(scene);
|
||||
},
|
||||
}).then((scene) => {
|
||||
initialStatePromiseRef.current.promise.resolve(scene);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue