fix: intercepter les requêtes webpack hot-update pour éviter les rechargements en boucle
- Interception de fetch et XMLHttpRequest pour bloquer les requêtes webpack.hot-update.json - Cela empêche Fast Refresh de déclencher des rechargements en boucle - Ajout de NEXT_DISABLE_FAST_REFRESH dans start-business.sh (si supporté par Next.js) - Les requêtes webpack hot-update sont maintenant ignorées silencieusement
This commit is contained in:
@@ -1,8 +1,50 @@
|
||||
// Script pour la gestion des pages de stratégie
|
||||
(function() {
|
||||
// Protection contre Fast Refresh : éviter les modifications DOM pendant le hot-reload
|
||||
if (window.__NEXT_DATA__ && window.__NEXT_DATA__.page === '/_error') {
|
||||
return; // Ne pas exécuter pendant les erreurs de rechargement
|
||||
// Protection contre Fast Refresh : ignorer les tentatives de hot-reload
|
||||
// Intercepter et ignorer les requêtes webpack hot-update pour éviter les rechargements en boucle
|
||||
if (typeof window !== 'undefined') {
|
||||
// Intercepter fetch
|
||||
const originalFetch = window.fetch;
|
||||
window.fetch = function(...args) {
|
||||
const url = args[0];
|
||||
if (typeof url === 'string' && url.includes('webpack.hot-update.json')) {
|
||||
// Ignorer silencieusement les requêtes webpack hot-update
|
||||
return Promise.resolve(new Response(JSON.stringify({}), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
}));
|
||||
}
|
||||
return originalFetch.apply(this, args);
|
||||
};
|
||||
|
||||
// Intercepter XMLHttpRequest (utilisé par Next.js pour Fast Refresh)
|
||||
const originalXHROpen = XMLHttpRequest.prototype.open;
|
||||
XMLHttpRequest.prototype.open = function(method, url, ...rest) {
|
||||
if (typeof url === 'string' && url.includes('webpack.hot-update.json')) {
|
||||
// Créer un faux XHR qui ne fait rien
|
||||
this._shouldIgnore = true;
|
||||
return;
|
||||
}
|
||||
return originalXHROpen.apply(this, [method, url, ...rest]);
|
||||
};
|
||||
|
||||
const originalXHRSend = XMLHttpRequest.prototype.send;
|
||||
XMLHttpRequest.prototype.send = function(...args) {
|
||||
if (this._shouldIgnore) {
|
||||
// Simuler une réponse réussie pour éviter les erreurs
|
||||
setTimeout(() => {
|
||||
if (this.onload) this.onload();
|
||||
if (this.onreadystatechange) {
|
||||
this.readyState = 4;
|
||||
this.status = 200;
|
||||
this.responseText = '{}';
|
||||
this.onreadystatechange();
|
||||
}
|
||||
}, 0);
|
||||
return;
|
||||
}
|
||||
return originalXHRSend.apply(this, args);
|
||||
};
|
||||
}
|
||||
|
||||
// --- DÉBUT PROTECTION MOT DE PASSE ---
|
||||
|
||||
Reference in New Issue
Block a user