MCPcopy
hub / github.com/vitejs/vite / fetchUpdate

Method fetchUpdate

packages/vite/src/shared/hmr.ts:264–308  ·  view source on GitHub ↗
(update: Update)

Source from the content-addressed store, hash-verified

262 }
263
264 private async fetchUpdate(update: Update): Promise<(() => void) | undefined> {
265 const { path, acceptedPath, firstInvalidatedBy } = update
266 const mod = this.hotModulesMap.get(path)
267 if (!mod) {
268 // In a code-splitting project,
269 // it is common that the hot-updating module is not loaded yet.
270 // https://github.com/vitejs/vite/issues/721
271 return
272 }
273
274 let fetchedModule: ModuleNamespace | undefined
275 const isSelfUpdate = path === acceptedPath
276
277 // determine the qualified callbacks before we re-import the modules
278 const qualifiedCallbacks = mod.callbacks.filter(({ deps }) =>
279 deps.includes(acceptedPath),
280 )
281
282 if (isSelfUpdate || qualifiedCallbacks.length > 0) {
283 const disposer = this.disposeMap.get(acceptedPath)
284 if (disposer) await disposer(this.dataMap.get(acceptedPath))
285 try {
286 fetchedModule = await this.importUpdatedModule(update)
287 } catch (e) {
288 this.warnFailedUpdate(e, acceptedPath)
289 }
290 }
291
292 return () => {
293 try {
294 this.currentFirstInvalidatedBy = firstInvalidatedBy
295 for (const { deps, fn } of qualifiedCallbacks) {
296 fn(
297 deps.map((dep) =>
298 dep === acceptedPath ? fetchedModule : undefined,
299 ),
300 )
301 }
302 const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`
303 this.logger.debug(`hot updated: ${loggedPath}`)
304 } finally {
305 this.currentFirstInvalidatedBy = undefined
306 }
307 }
308 }
309}

Callers 1

queueUpdateMethod · 0.95

Calls 4

warnFailedUpdateMethod · 0.95
debugMethod · 0.65
fnFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected