Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: race condition creation module in graph in transformRequest #13085

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions packages/vite/src/node/server/transformRequest.ts
Expand Up @@ -3,7 +3,7 @@ import path from 'node:path'
import { performance } from 'node:perf_hooks'
import getEtag from 'etag'
import convertSourceMap from 'convert-source-map'
import type { SourceDescription, SourceMap } from 'rollup'
import type { PartialResolvedId, SourceDescription, SourceMap } from 'rollup'
import colors from 'picocolors'
import type { ModuleNode, ViteDevServer } from '..'
import {
Expand Down Expand Up @@ -141,13 +141,22 @@ async function doTransform(
return cached
}

const resolved = module
? undefined
: (await pluginContainer.resolveId(url, undefined, { ssr })) ?? undefined

// resolve
const id =
module?.id ??
(await pluginContainer.resolveId(url, undefined, { ssr }))?.id ??
url
const id = module?.id ?? resolved?.id ?? url

const result = loadAndTransform(id, url, server, options, timestamp)
const result = loadAndTransform(
id,
url,
server,
options,
timestamp,
module,
resolved,
)

getDepsOptimizer(config, ssr)?.delayDepsOptimizerUntil(id, () => result)

Expand All @@ -160,6 +169,8 @@ async function loadAndTransform(
server: ViteDevServer,
options: TransformOptions,
timestamp: number,
mod?: ModuleNode,
resolved?: PartialResolvedId,
) {
const { config, pluginContainer, moduleGraph, watcher } = server
const { root, logger } = config
Expand Down Expand Up @@ -243,7 +254,7 @@ async function loadAndTransform(
throw err
}
// ensure module in graph after successful load
const mod = await moduleGraph.ensureEntryFromUrl(url, ssr)
mod ??= await moduleGraph._ensureEntryFromUrl(url, ssr, undefined, resolved)
ensureWatchedFile(watcher, mod.file, root)

// transform
Expand Down