Home / Function/ cachedRequest() — vite Function Reference

cachedRequest() — vite Function Reference

Architecture documentation for the cachedRequest() function in runner.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  80e2d448_2bda_f3ef_d790_a8b2d8bcb44e["cachedRequest()"]
  1d3ff778_7ac6_0038_640f_997e968c3c8f["ModuleRunner"]
  80e2d448_2bda_f3ef_d790_a8b2d8bcb44e -->|defined in| 1d3ff778_7ac6_0038_640f_997e968c3c8f
  bb00524b_0245_2d21_5a59_2a82dd570676["import()"]
  bb00524b_0245_2d21_5a59_2a82dd570676 -->|calls| 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e
  2299eb48_afeb_b0e8_8b25_f24d005c00d4["directRequest()"]
  2299eb48_afeb_b0e8_8b25_f24d005c00d4 -->|calls| 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e
  62a26ebe_568c_7e40_6141_02c130e85f05["isCircularModule()"]
  80e2d448_2bda_f3ef_d790_a8b2d8bcb44e -->|calls| 62a26ebe_568c_7e40_6141_02c130e85f05
  fa390543_1809_cca2_86cc_652c388b3899["isCircularImport()"]
  80e2d448_2bda_f3ef_d790_a8b2d8bcb44e -->|calls| fa390543_1809_cca2_86cc_652c388b3899
  5545fcba_59d0_ba73_89b7_11f4c41391bd["processImport()"]
  80e2d448_2bda_f3ef_d790_a8b2d8bcb44e -->|calls| 5545fcba_59d0_ba73_89b7_11f4c41391bd
  2299eb48_afeb_b0e8_8b25_f24d005c00d4["directRequest()"]
  80e2d448_2bda_f3ef_d790_a8b2d8bcb44e -->|calls| 2299eb48_afeb_b0e8_8b25_f24d005c00d4
  style 80e2d448_2bda_f3ef_d790_a8b2d8bcb44e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/module-runner/runner.ts lines 170–222

  private async cachedRequest(
    url: string,
    mod: EvaluatedModuleNode,
    callstack: string[] = [],
    metadata?: SSRImportMetadata,
  ): Promise<any> {
    const meta = mod.meta!
    const moduleId = meta.id

    const { importers } = mod

    const importee = callstack[callstack.length - 1]

    if (importee) importers.add(importee)

    // check circular dependency
    if (
      callstack.includes(moduleId) ||
      this.isCircularModule(mod) ||
      this.isCircularImport(importers, moduleId)
    ) {
      if (mod.exports) return this.processImport(mod.exports, meta, metadata)
    }

    let debugTimer: any
    if (this.debug) {
      debugTimer = setTimeout(() => {
        const getStack = () =>
          `stack:\n${[...callstack, moduleId]
            .reverse()
            .map((p) => `  - ${p}`)
            .join('\n')}`

        this.debug!(
          `[module runner] module ${moduleId} takes over 2s to load.\n${getStack()}`,
        )
      }, 2000)
    }

    try {
      // cached module
      if (mod.promise)
        return this.processImport(await mod.promise, meta, metadata)

      const promise = this.directRequest(url, mod, callstack)
      mod.promise = promise
      mod.evaluated = false
      return this.processImport(await promise, meta, metadata)
    } finally {
      mod.evaluated = true
      if (debugTimer) clearTimeout(debugTimer)
    }
  }

Domain

Subdomains

Frequently Asked Questions

What does cachedRequest() do?
cachedRequest() is a function in the vite codebase, defined in packages/vite/src/module-runner/runner.ts.
Where is cachedRequest() defined?
cachedRequest() is defined in packages/vite/src/module-runner/runner.ts at line 170.
What does cachedRequest() call?
cachedRequest() calls 4 function(s): directRequest, isCircularImport, isCircularModule, processImport.
What calls cachedRequest()?
cachedRequest() is called by 2 function(s): directRequest, import.

Analyze Your Own Codebase

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

Try Supermodel Free