|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import RefreshRuntime from 'react-refresh/runtime' |
|
|
|
|
|
type ModuleHotStatus = |
|
|
| 'idle' |
|
|
| 'check' |
|
|
| 'prepare' |
|
|
| 'ready' |
|
|
| 'dispose' |
|
|
| 'apply' |
|
|
| 'abort' |
|
|
| 'fail' |
|
|
|
|
|
type ModuleHotStatusHandler = (status: ModuleHotStatus) => void |
|
|
|
|
|
declare const module: { |
|
|
hot: { |
|
|
status: () => ModuleHotStatus |
|
|
addStatusHandler: (handler: ModuleHotStatusHandler) => void |
|
|
removeStatusHandler: (handler: ModuleHotStatusHandler) => void |
|
|
} |
|
|
} |
|
|
|
|
|
function isSafeExport(key: string): boolean { |
|
|
return ( |
|
|
key === '__esModule' || |
|
|
key === '__N_SSG' || |
|
|
key === '__N_SSP' || |
|
|
|
|
|
key === 'config' |
|
|
) |
|
|
} |
|
|
|
|
|
function registerExportsForReactRefresh( |
|
|
moduleExports: unknown, |
|
|
moduleID: string |
|
|
) { |
|
|
RefreshRuntime.register(moduleExports, moduleID + ' %exports%') |
|
|
if (moduleExports == null || typeof moduleExports !== 'object') { |
|
|
|
|
|
|
|
|
return |
|
|
} |
|
|
for (var key in moduleExports) { |
|
|
if (isSafeExport(key)) { |
|
|
continue |
|
|
} |
|
|
try { |
|
|
var exportValue = moduleExports[key] |
|
|
} catch { |
|
|
|
|
|
continue |
|
|
} |
|
|
var typeID = moduleID + ' %exports% ' + key |
|
|
RefreshRuntime.register(exportValue, typeID) |
|
|
} |
|
|
} |
|
|
|
|
|
function getRefreshBoundarySignature(moduleExports: unknown): Array<unknown> { |
|
|
var signature = [] |
|
|
signature.push(RefreshRuntime.getFamilyByType(moduleExports)) |
|
|
if (moduleExports == null || typeof moduleExports !== 'object') { |
|
|
|
|
|
|
|
|
return signature |
|
|
} |
|
|
for (var key in moduleExports) { |
|
|
if (isSafeExport(key)) { |
|
|
continue |
|
|
} |
|
|
try { |
|
|
var exportValue = moduleExports[key] |
|
|
} catch { |
|
|
|
|
|
continue |
|
|
} |
|
|
signature.push(key) |
|
|
signature.push(RefreshRuntime.getFamilyByType(exportValue)) |
|
|
} |
|
|
return signature |
|
|
} |
|
|
|
|
|
function isReactRefreshBoundary(moduleExports: unknown): boolean { |
|
|
if (RefreshRuntime.isLikelyComponentType(moduleExports)) { |
|
|
return true |
|
|
} |
|
|
if (moduleExports == null || typeof moduleExports !== 'object') { |
|
|
|
|
|
return false |
|
|
} |
|
|
var hasExports = false |
|
|
var areAllExportsComponents = true |
|
|
for (var key in moduleExports) { |
|
|
hasExports = true |
|
|
if (isSafeExport(key)) { |
|
|
continue |
|
|
} |
|
|
try { |
|
|
var exportValue = moduleExports[key] |
|
|
} catch { |
|
|
|
|
|
return false |
|
|
} |
|
|
if (!RefreshRuntime.isLikelyComponentType(exportValue)) { |
|
|
areAllExportsComponents = false |
|
|
} |
|
|
} |
|
|
return hasExports && areAllExportsComponents |
|
|
} |
|
|
|
|
|
function shouldInvalidateReactRefreshBoundary( |
|
|
prevSignature: unknown[], |
|
|
nextSignature: unknown[] |
|
|
): boolean { |
|
|
if (prevSignature.length !== nextSignature.length) { |
|
|
return true |
|
|
} |
|
|
for (var i = 0; i < nextSignature.length; i++) { |
|
|
if (prevSignature[i] !== nextSignature[i]) { |
|
|
return true |
|
|
} |
|
|
} |
|
|
return false |
|
|
} |
|
|
|
|
|
var isUpdateScheduled: boolean = false |
|
|
|
|
|
function scheduleUpdate() { |
|
|
if (isUpdateScheduled) { |
|
|
return |
|
|
} |
|
|
isUpdateScheduled = true |
|
|
|
|
|
function canApplyUpdate(status: ModuleHotStatus) { |
|
|
return status === 'idle' |
|
|
} |
|
|
|
|
|
function applyUpdate() { |
|
|
isUpdateScheduled = false |
|
|
try { |
|
|
RefreshRuntime.performReactRefresh() |
|
|
} catch (err) { |
|
|
console.warn( |
|
|
'Warning: Failed to re-render. We will retry on the next Fast Refresh event.\n' + |
|
|
err |
|
|
) |
|
|
} |
|
|
} |
|
|
|
|
|
if (canApplyUpdate(module.hot.status())) { |
|
|
|
|
|
Promise.resolve().then(() => { |
|
|
applyUpdate() |
|
|
}) |
|
|
return |
|
|
} |
|
|
|
|
|
const statusHandler = (status) => { |
|
|
if (canApplyUpdate(status)) { |
|
|
module.hot.removeStatusHandler(statusHandler) |
|
|
applyUpdate() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
module.hot.addStatusHandler(statusHandler) |
|
|
} |
|
|
|
|
|
|
|
|
export default { |
|
|
registerExportsForReactRefresh: registerExportsForReactRefresh, |
|
|
isReactRefreshBoundary: isReactRefreshBoundary, |
|
|
shouldInvalidateReactRefreshBoundary: shouldInvalidateReactRefreshBoundary, |
|
|
getRefreshBoundarySignature: getRefreshBoundarySignature, |
|
|
scheduleUpdate: scheduleUpdate, |
|
|
} |
|
|
|