From 2da07a8d0100ad1f9c19323363d7f1e456cf538b Mon Sep 17 00:00:00 2001 From: thislight Date: Fri, 27 Dec 2024 21:40:39 +0800 Subject: [PATCH] Settings: correct safe area emu hot reload --- src/settings/Settings.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index f783e7a..645c98f 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -141,11 +141,16 @@ function setupSafeAreaEmulation(name: string) { } } +const $$SAFE_AREA_EMU = "$$SAFE_AREA_EMU"; + if (import.meta.hot) { - import.meta.hot.accept((mod) => { - if (!mod) return; + import.meta.hot.on("vite:beforeUpdate", () => { + import.meta.hot!.data[$$SAFE_AREA_EMU] = screenOrientationCallback; + }); + + import.meta.hot.on("vite:afterUpdate", () => { + screenOrientationCallback = import.meta.hot?.data?.[$$SAFE_AREA_EMU]; if (screenOrientationCallback) { - mod["screenOrientationCallback"] = screenOrientationCallback; setTimeout(screenOrientationCallback, 0); } });