Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,25 @@ export function transformRequest(
// last time this module is invalidated
const timestamp = monotonicDateNow()

url = removeTimestampQuery(url)

const pending = environment._pendingRequests.get(url)
if (pending) {
return environment.moduleGraph
.getModuleByUrl(removeTimestampQuery(url))
.then((module) => {
if (!module || pending.timestamp > module.lastInvalidationTimestamp) {
// The pending request is still valid, we can safely reuse its result
return pending.request
} else {
// Request 1 for module A (pending.timestamp)
// Invalidate module A (module.lastInvalidationTimestamp)
// Request 2 for module A (timestamp)

// First request has been invalidated, abort it to clear the cache,
// then perform a new doTransform.
pending.abort()
return transformRequest(environment, url, options)
}
})
return environment.moduleGraph.getModuleByUrl(url).then((module) => {
if (!module || pending.timestamp > module.lastInvalidationTimestamp) {
// The pending request is still valid, we can safely reuse its result
return pending.request
} else {
// Request 1 for module A (pending.timestamp)
// Invalidate module A (module.lastInvalidationTimestamp)
// Request 2 for module A (timestamp)

// First request has been invalidated, abort it to clear the cache,
// then perform a new doTransform.
pending.abort()
return transformRequest(environment, url, options)
}
})
}

const request = doTransform(environment, url, options, timestamp)
Expand Down Expand Up @@ -147,8 +147,6 @@ async function doTransform(
options: TransformOptionsInternal,
timestamp: number,
) {
url = removeTimestampQuery(url)

const { pluginContainer } = environment

let module = await environment.moduleGraph.getModuleByUrl(url)
Expand Down