@@ -28,11 +28,27 @@ const GlobalError: React.FC<{
2828 const [ isRecovering , setIsRecovering ] = useState ( false ) ;
2929
3030 useEffect ( ( ) => {
31+ // Check if the error is likely due to being offline (e.g., failed to load a JS chunk)
32+ const isOfflineError =
33+ ! navigator . onLine ||
34+ error . name === 'ChunkLoadError' ||
35+ error . message . toLowerCase ( ) . includes ( 'failed to fetch' ) ||
36+ error . message . toLowerCase ( ) . includes ( 'network error' ) ;
37+
38+ // Completely disable global offline redirection for the Payload CMS admin panel.
39+ // Payload has its own offline handling and error boundaries.
40+ const isAdminPanel =
41+ typeof globalThis !== 'undefined' && globalThis . location . pathname . startsWith ( '/admin' ) ;
42+
3143 // In draft/preview mode, auto-reload instead of showing the error page.
3244 // This prevents the Payload CMS Live Preview iframe from getting stuck.
33- if ( isDraftOrPreviewMode ( ) ) {
45+ // We also do this for transient network errors in the admin panel to prevent the
46+ // root error boundary from permanently replacing the admin UI with a red error screen.
47+ const isTransientAdminError = isAdminPanel && isOfflineError ;
48+
49+ if ( isDraftOrPreviewMode ( ) || isTransientAdminError ) {
3450 console . warn (
35- '[GlobalError] Transient error in draft /preview mode. Auto-reloading in 2s:' ,
51+ '[GlobalError] Transient error in admin /preview mode. Auto-reloading in 2s:' ,
3652 error . message ,
3753 ) ;
3854 setIsRecovering ( true ) ;
@@ -44,14 +60,7 @@ const GlobalError: React.FC<{
4460 } ;
4561 }
4662
47- // Check if the error is likely due to being offline (e.g., failed to load a JS chunk)
48- const isOfflineError =
49- ! navigator . onLine ||
50- error . name === 'ChunkLoadError' ||
51- error . message . toLowerCase ( ) . includes ( 'failed to fetch' ) ||
52- error . message . toLowerCase ( ) . includes ( 'network error' ) ;
53-
54- if ( isOfflineError ) {
63+ if ( isOfflineError && ! isAdminPanel ) {
5564 console . error ( '[GlobalError] Network/Offline error detected:' , {
5665 message : error . message ,
5766 name : error . name ,
0 commit comments