Home / Function/ fetchUpdate() — vite Function Reference

fetchUpdate() — vite Function Reference

Architecture documentation for the fetchUpdate() function in hmr.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  c63a9132_545b_01b5_04fc_03798c19ef8d["fetchUpdate()"]
  59034bde_6f4e_fe6a_b2ce_a002a0aa10b4["HMRClient"]
  c63a9132_545b_01b5_04fc_03798c19ef8d -->|defined in| 59034bde_6f4e_fe6a_b2ce_a002a0aa10b4
  dc6afbd1_68d8_b85c_ede6_e2f3839fdccd["queueUpdate()"]
  dc6afbd1_68d8_b85c_ede6_e2f3839fdccd -->|calls| c63a9132_545b_01b5_04fc_03798c19ef8d
  5d31dedf_6209_3e74_e70e_b1abf8629e61["warnFailedUpdate()"]
  c63a9132_545b_01b5_04fc_03798c19ef8d -->|calls| 5d31dedf_6209_3e74_e70e_b1abf8629e61
  style c63a9132_545b_01b5_04fc_03798c19ef8d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/shared/hmr.ts lines 264–308

  private async fetchUpdate(update: Update): Promise<(() => void) | undefined> {
    const { path, acceptedPath, firstInvalidatedBy } = update
    const mod = this.hotModulesMap.get(path)
    if (!mod) {
      // In a code-splitting project,
      // it is common that the hot-updating module is not loaded yet.
      // https://github.com/vitejs/vite/issues/721
      return
    }

    let fetchedModule: ModuleNamespace | undefined
    const isSelfUpdate = path === acceptedPath

    // determine the qualified callbacks before we re-import the modules
    const qualifiedCallbacks = mod.callbacks.filter(({ deps }) =>
      deps.includes(acceptedPath),
    )

    if (isSelfUpdate || qualifiedCallbacks.length > 0) {
      const disposer = this.disposeMap.get(acceptedPath)
      if (disposer) await disposer(this.dataMap.get(acceptedPath))
      try {
        fetchedModule = await this.importUpdatedModule(update)
      } catch (e) {
        this.warnFailedUpdate(e, acceptedPath)
      }
    }

    return () => {
      try {
        this.currentFirstInvalidatedBy = firstInvalidatedBy
        for (const { deps, fn } of qualifiedCallbacks) {
          fn(
            deps.map((dep) =>
              dep === acceptedPath ? fetchedModule : undefined,
            ),
          )
        }
        const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`
        this.logger.debug(`hot updated: ${loggedPath}`)
      } finally {
        this.currentFirstInvalidatedBy = undefined
      }
    }
  }

Domain

Subdomains

Called By

Frequently Asked Questions

What does fetchUpdate() do?
fetchUpdate() is a function in the vite codebase, defined in packages/vite/src/shared/hmr.ts.
Where is fetchUpdate() defined?
fetchUpdate() is defined in packages/vite/src/shared/hmr.ts at line 264.
What does fetchUpdate() call?
fetchUpdate() calls 1 function(s): warnFailedUpdate.
What calls fetchUpdate()?
fetchUpdate() is called by 1 function(s): queueUpdate.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free