From 991f5e8172706f600d5da5e9004f57900e2809f0 Mon Sep 17 00:00:00 2001 From: Ayu Date: Mon, 24 Jun 2024 15:54:49 +0100 Subject: [PATCH] fix(dashboard): undefined loader error in spa from bad cookie cache (#43) --- dashboard/app/root.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dashboard/app/root.tsx b/dashboard/app/root.tsx index 4fbf5b68..3af88412 100644 --- a/dashboard/app/root.tsx +++ b/dashboard/app/root.tsx @@ -67,7 +67,7 @@ import { NotFoundError, } from '@/components/layout/Error'; import theme from '@/styles/theme'; -import { hasSession } from '@/utils/cookies'; +import { EXPIRE_LOGGED_IN, hasSession } from '@/utils/cookies'; interface LoaderData { isLoggedIn: boolean; @@ -199,6 +199,15 @@ export const ErrorBoundary = () => { } if (error instanceof Error) { + // If the error is due to a loader mismatch, reload the page as it may be + // related to a bad cookie cache from the API restarting. This is probably + // a bug in Remix SPA mode. + if (error.message.startsWith('You defined a loader for route "routes')) { + document.cookie = EXPIRE_LOGGED_IN; + window.location.reload(); + return HydrateFallback(); + } + return (