Skip to content

The open alternative to Salesforce, designed for AI.

Fix Vite stale chunk lazy loading error. (#12984)

Lucas Bordeaue832a3a6093f
diff --git a/packages/twenty-front/src/modules/error-handler/components/AppErrorBoundary.tsx b/packages/twenty-front/src/modules/error-handler/components/AppErrorBoundary.tsx
index d2d95b7e66e..b3c81959ae8 100644
--- a/packages/twenty-front/src/modules/error-handler/components/AppErrorBoundary.tsx
+++ b/packages/twenty-front/src/modules/error-handler/components/AppErrorBoundary.tsx
@@ -1,5 +1,6 @@
import { AppErrorBoundaryEffect } from '@/error-handler/components/internal/AppErrorBoundaryEffect';
import { CustomError } from '@/error-handler/CustomError';
+import { checkIfItsAViteStaleChunkLazyLoadingError } from '@/error-handler/utils/checkIfItsAViteStaleChunkLazyLoadingError';
import { ErrorInfo, ReactNode } from 'react';
import { ErrorBoundary, FallbackProps } from 'react-error-boundary';
import { isDefined } from 'twenty-shared/utils';
@@ -36,6 +37,13 @@ export const AppErrorBoundary = ({
// eslint-disable-next-line no-console
console.error('Failed to capture exception with Sentry:', sentryError);
}
+
+ const isViteStaleChunkLazyLoadingError =
+ checkIfItsAViteStaleChunkLazyLoadingError(error);
+
+ if (isViteStaleChunkLazyLoadingError) {
+ window.location.reload();
+ }
};
const handleReset = () => {
diff --git a/packages/twenty-front/src/modules/error-handler/utils/checkIfItsAViteStaleChunkLazyLoadingError.ts b/packages/twenty-front/src/modules/error-handler/utils/checkIfItsAViteStaleChunkLazyLoadingError.ts
new file mode 100644
index 00000000000..39dd2f8aa83
--- /dev/null
+++ b/packages/twenty-front/src/modules/error-handler/utils/checkIfItsAViteStaleChunkLazyLoadingError.ts
@@ -0,0 +1,3 @@
+export const checkIfItsAViteStaleChunkLazyLoadingError = (error: Error) => {
+ return error.message.includes('Failed to fetch dynamically imported module');
+};