diff --git a/src/app/App.tsx b/src/app/App.tsx index d40269f2..f6b98798 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -12,9 +12,26 @@ import OAuthCallback from "./pages/OAuthCallback"; import JiraCallback from "./pages/JiraCallback"; import PrivacyPage from "./pages/PrivacyPage"; -const DashboardPage = lazy(() => import("./components/dashboard/DashboardPage")); -const OnboardingWizard = lazy(() => import("./components/onboarding/OnboardingWizard")); -const SettingsPage = lazy(() => import("./components/settings/SettingsPage")); +const CHUNK_RELOAD_KEY = "github-tracker:chunk-reload"; +const CHUNK_RELOAD_MAX_AGE = 10_000; + +function lazyWithReload(loader: Parameters[0]) { + return lazy(() => + loader().catch((err) => { + const last = sessionStorage.getItem(CHUNK_RELOAD_KEY); + if (!last || Date.now() - Number(last) > CHUNK_RELOAD_MAX_AGE) { + sessionStorage.setItem(CHUNK_RELOAD_KEY, String(Date.now())); + window.location.reload(); + return new Promise(() => {}); + } + throw err; + }), + ); +} + +const DashboardPage = lazyWithReload(() => import("./components/dashboard/DashboardPage")); +const OnboardingWizard = lazyWithReload(() => import("./components/onboarding/OnboardingWizard")); +const SettingsPage = lazyWithReload(() => import("./components/settings/SettingsPage")); const SentryErrorBoundary = Sentry.withSentryErrorBoundary(ErrorBoundary);