|
|
|
|
|
|
|
|
const events = require('./utils/errorEventHandlers.js'); |
|
|
const formatWebpackErrors = require('./utils/formatWebpackErrors.js'); |
|
|
const runWithPatchedUrl = require('./utils/patchUrl.js'); |
|
|
const runWithRetry = require('./utils/retry.js'); |
|
|
|
|
|
|
|
|
let isHotReload = false; |
|
|
let hasRuntimeErrors = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function tryDismissErrorOverlay() { |
|
|
__react_refresh_error_overlay__.clearCompileError(); |
|
|
__react_refresh_error_overlay__.clearRuntimeErrors(!hasRuntimeErrors); |
|
|
hasRuntimeErrors = false; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleCompileSuccess() { |
|
|
isHotReload = true; |
|
|
|
|
|
if (isHotReload) { |
|
|
tryDismissErrorOverlay(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function handleCompileErrors(errors) { |
|
|
isHotReload = true; |
|
|
|
|
|
const formattedErrors = formatWebpackErrors(errors); |
|
|
|
|
|
|
|
|
__react_refresh_error_overlay__.showCompileError(formattedErrors[0]); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function compileMessageHandler(message) { |
|
|
switch (message.type) { |
|
|
case 'ok': |
|
|
case 'still-ok': |
|
|
case 'warnings': { |
|
|
|
|
|
handleCompileSuccess(); |
|
|
break; |
|
|
} |
|
|
case 'errors': { |
|
|
handleCompileErrors(message.data); |
|
|
break; |
|
|
} |
|
|
default: { |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') { |
|
|
if (typeof window !== 'undefined') { |
|
|
runWithPatchedUrl(function setupOverlay() { |
|
|
|
|
|
if (!window.__reactRefreshOverlayInjected && __react_refresh_socket__) { |
|
|
|
|
|
|
|
|
runWithRetry(function initSocket() { |
|
|
__react_refresh_socket__.init(compileMessageHandler, __resourceQuery); |
|
|
}, 3); |
|
|
|
|
|
events.handleError(function handleError(error) { |
|
|
hasRuntimeErrors = true; |
|
|
__react_refresh_error_overlay__.handleRuntimeError(error); |
|
|
}); |
|
|
events.handleUnhandledRejection(function handleUnhandledPromiseRejection(error) { |
|
|
hasRuntimeErrors = true; |
|
|
__react_refresh_error_overlay__.handleRuntimeError(error); |
|
|
}); |
|
|
|
|
|
|
|
|
window.__reactRefreshOverlayInjected = true; |
|
|
} |
|
|
}); |
|
|
} |
|
|
} |
|
|
|