🔧
This commit is contained in:
83
node_modules/vite/dist/client/client.mjs
generated
vendored
83
node_modules/vite/dist/client/client.mjs
generated
vendored
@@ -56,13 +56,16 @@ class HMRContext {
|
||||
decline() {
|
||||
}
|
||||
invalidate(message) {
|
||||
const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
|
||||
this.hmrClient.notifyListeners("vite:invalidate", {
|
||||
path: this.ownerPath,
|
||||
message
|
||||
message,
|
||||
firstInvalidatedBy
|
||||
});
|
||||
this.send("vite:invalidate", {
|
||||
path: this.ownerPath,
|
||||
message
|
||||
message,
|
||||
firstInvalidatedBy
|
||||
});
|
||||
this.hmrClient.logger.debug(
|
||||
`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
|
||||
@@ -160,7 +163,7 @@ class HMRClient {
|
||||
});
|
||||
}
|
||||
warnFailedUpdate(err, path) {
|
||||
if (!err.message.includes("fetch")) {
|
||||
if (!(err instanceof Error) || !err.message.includes("fetch")) {
|
||||
this.logger.error(err);
|
||||
}
|
||||
this.logger.error(
|
||||
@@ -184,7 +187,7 @@ class HMRClient {
|
||||
}
|
||||
}
|
||||
async fetchUpdate(update) {
|
||||
const { path, acceptedPath } = update;
|
||||
const { path, acceptedPath, firstInvalidatedBy } = update;
|
||||
const mod = this.hotModulesMap.get(path);
|
||||
if (!mod) {
|
||||
return;
|
||||
@@ -204,13 +207,20 @@ class HMRClient {
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
for (const { deps, fn } of qualifiedCallbacks) {
|
||||
fn(
|
||||
deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
|
||||
);
|
||||
try {
|
||||
this.currentFirstInvalidatedBy = firstInvalidatedBy;
|
||||
for (const { deps, fn } of qualifiedCallbacks) {
|
||||
fn(
|
||||
deps.map(
|
||||
(dep) => dep === acceptedPath ? fetchedModule : void 0
|
||||
)
|
||||
);
|
||||
}
|
||||
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
||||
this.logger.debug(`hot updated: ${loggedPath}`);
|
||||
} finally {
|
||||
this.currentFirstInvalidatedBy = void 0;
|
||||
}
|
||||
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
||||
this.logger.debug(`hot updated: ${loggedPath}`);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -475,6 +485,42 @@ const createWebSocketModuleRunnerTransport = (options) => {
|
||||
};
|
||||
};
|
||||
|
||||
function createHMRHandler(handler) {
|
||||
const queue = new Queue();
|
||||
return (payload) => queue.enqueue(() => handler(payload));
|
||||
}
|
||||
class Queue {
|
||||
constructor() {
|
||||
this.queue = [];
|
||||
this.pending = false;
|
||||
}
|
||||
enqueue(promise) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.queue.push({
|
||||
promise,
|
||||
resolve,
|
||||
reject
|
||||
});
|
||||
this.dequeue();
|
||||
});
|
||||
}
|
||||
dequeue() {
|
||||
if (this.pending) {
|
||||
return false;
|
||||
}
|
||||
const item = this.queue.shift();
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
this.pending = true;
|
||||
item.promise().then(item.resolve).catch(item.reject).finally(() => {
|
||||
this.pending = false;
|
||||
this.dequeue();
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const hmrConfigName = __HMR_CONFIG_NAME__;
|
||||
const base$1 = __BASE__ || "/";
|
||||
function h(e, attrs = {}, ...children) {
|
||||
@@ -859,14 +905,14 @@ const hmrClient = new HMRClient(
|
||||
return await importPromise;
|
||||
}
|
||||
);
|
||||
transport.connect(handleMessage);
|
||||
transport.connect(createHMRHandler(handleMessage));
|
||||
async function handleMessage(payload) {
|
||||
switch (payload.type) {
|
||||
case "connected":
|
||||
console.debug(`[vite] connected.`);
|
||||
break;
|
||||
case "update":
|
||||
notifyListeners("vite:beforeUpdate", payload);
|
||||
await hmrClient.notifyListeners("vite:beforeUpdate", payload);
|
||||
if (hasDocument) {
|
||||
if (isFirstUpdate && hasErrorOverlay()) {
|
||||
location.reload();
|
||||
@@ -909,10 +955,10 @@ async function handleMessage(payload) {
|
||||
});
|
||||
})
|
||||
);
|
||||
notifyListeners("vite:afterUpdate", payload);
|
||||
await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
||||
break;
|
||||
case "custom": {
|
||||
notifyListeners(payload.event, payload.data);
|
||||
await hmrClient.notifyListeners(payload.event, payload.data);
|
||||
if (payload.event === "vite:ws:disconnect") {
|
||||
if (hasDocument && !willUnload) {
|
||||
console.log(`[vite] server connection lost. Polling for restart...`);
|
||||
@@ -926,7 +972,7 @@ async function handleMessage(payload) {
|
||||
break;
|
||||
}
|
||||
case "full-reload":
|
||||
notifyListeners("vite:beforeFullReload", payload);
|
||||
await hmrClient.notifyListeners("vite:beforeFullReload", payload);
|
||||
if (hasDocument) {
|
||||
if (payload.path && payload.path.endsWith(".html")) {
|
||||
const pagePath = decodeURI(location.pathname);
|
||||
@@ -941,11 +987,11 @@ async function handleMessage(payload) {
|
||||
}
|
||||
break;
|
||||
case "prune":
|
||||
notifyListeners("vite:beforePrune", payload);
|
||||
await hmrClient.notifyListeners("vite:beforePrune", payload);
|
||||
await hmrClient.prunePaths(payload.paths);
|
||||
break;
|
||||
case "error": {
|
||||
notifyListeners("vite:error", payload);
|
||||
await hmrClient.notifyListeners("vite:error", payload);
|
||||
if (hasDocument) {
|
||||
const err = payload.err;
|
||||
if (enableOverlay) {
|
||||
@@ -968,9 +1014,6 @@ ${err.stack}`
|
||||
}
|
||||
}
|
||||
}
|
||||
function notifyListeners(event, data) {
|
||||
hmrClient.notifyListeners(event, data);
|
||||
}
|
||||
const enableOverlay = __HMR_ENABLE_OVERLAY__;
|
||||
const hasDocument = "document" in globalThis;
|
||||
function createErrorOverlay(err) {
|
||||
|
||||
Reference in New Issue
Block a user