fix: 500ms delay on focus reload — wait for other tab's blur save
Some checks failed
CI/CD — Build & Deploy / Build & Deploy (push) Failing after 17s
Some checks failed
CI/CD — Build & Deploy / Build & Deploy (push) Failing after 17s
This commit is contained in:
@@ -95,7 +95,8 @@ export function useSaveSync({ getGameState, onLoad, playTimeSeconds }: SaveSyncO
|
|||||||
if (!user) return undefined;
|
if (!user) return undefined;
|
||||||
|
|
||||||
const handleFocus = () => {
|
const handleFocus = () => {
|
||||||
apiRequest("/save").then((data) => {
|
// Small delay to let the other tab's blur save complete
|
||||||
|
setTimeout(() => apiRequest("/save").then((data) => {
|
||||||
if (data?.gameState && data.lastSave) {
|
if (data?.gameState && data.lastSave) {
|
||||||
if (!lastSaveRef.current || new Date(data.lastSave) > new Date(lastSaveRef.current)) {
|
if (!lastSaveRef.current || new Date(data.lastSave) > new Date(lastSaveRef.current)) {
|
||||||
onLoad(data.gameState);
|
onLoad(data.gameState);
|
||||||
@@ -103,7 +104,7 @@ export function useSaveSync({ getGameState, onLoad, playTimeSeconds }: SaveSyncO
|
|||||||
console.info("[SaveSync] Reloaded from server on focus");
|
console.info("[SaveSync] Reloaded from server on focus");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}), 500);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleBlur = () => {
|
const handleBlur = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user