Fix mobile Safari reload loop by persisting config cache in window object
All checks were successful
Build And Push Image / docker (push) Successful in 2m56s
All checks were successful
Build And Push Image / docker (push) Successful in 2m56s
- Store config cache in window.__configCache instead of module-level variable to maintain persistence across Vue reactivity cycles - Fix cardClasses ref to store computed value instead of function - Add client plugin for config cache initialization - Add documentation for mobile Safari reload loop fix
This commit is contained in:
79
plugins/04.config-cache-init.client.ts
Normal file
79
plugins/04.config-cache-init.client.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* Config Cache Initialization Plugin
|
||||
* Ensures config cache is properly initialized and prevents reload loops
|
||||
* Specifically designed to fix Safari iOS issues
|
||||
*/
|
||||
|
||||
export default defineNuxtPlugin({
|
||||
name: 'config-cache-init',
|
||||
enforce: 'pre', // Run before other plugins
|
||||
async setup() {
|
||||
console.log('[config-cache-init] Initializing config cache plugin');
|
||||
|
||||
// Only run on client side
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize a flag to prevent multiple initializations
|
||||
if ((window as any).__configCacheInitialized) {
|
||||
console.log('[config-cache-init] Config cache already initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark as initialized
|
||||
(window as any).__configCacheInitialized = true;
|
||||
|
||||
// Initialize the config cache structure if not already present
|
||||
if (!(window as any).__configCache) {
|
||||
(window as any).__configCache = {
|
||||
recaptcha: null,
|
||||
registration: null,
|
||||
recaptchaLoading: false,
|
||||
registrationLoading: false,
|
||||
recaptchaError: null,
|
||||
registrationError: null
|
||||
};
|
||||
console.log('[config-cache-init] Config cache structure initialized');
|
||||
}
|
||||
|
||||
// Initialize call history for circuit breaker
|
||||
if (!(window as any).__configCallHistory) {
|
||||
(window as any).__configCallHistory = {};
|
||||
console.log('[config-cache-init] Call history initialized');
|
||||
}
|
||||
|
||||
// Add a global error handler to catch and prevent reload loops
|
||||
const originalError = window.onerror;
|
||||
window.onerror = function(msg, url, lineNo, columnNo, error) {
|
||||
// Check for common reload loop patterns
|
||||
if (typeof msg === 'string' && (
|
||||
msg.includes('Maximum call stack') ||
|
||||
msg.includes('too much recursion') ||
|
||||
msg.includes('RangeError')
|
||||
)) {
|
||||
console.error('[config-cache-init] Potential reload loop detected:', msg);
|
||||
// Prevent default error handling which might cause reload
|
||||
return true;
|
||||
}
|
||||
|
||||
// Call original error handler if it exists
|
||||
if (originalError) {
|
||||
return originalError(msg, url, lineNo, columnNo, error);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// Add unhandled rejection handler
|
||||
window.addEventListener('unhandledrejection', (event) => {
|
||||
if (event.reason?.message?.includes('config') ||
|
||||
event.reason?.message?.includes('reload')) {
|
||||
console.error('[config-cache-init] Unhandled config-related rejection:', event.reason);
|
||||
// Prevent default which might cause reload
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
console.log('[config-cache-init] Config cache plugin initialized successfully');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user