Skip to content

Commit

Permalink
fix: deps optimizer should wait on entries (#8822)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Jun 28, 2022
1 parent 2061d41 commit 2db1b5b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
5 changes: 1 addition & 4 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -696,17 +696,14 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
NULL_BYTE_PLACEHOLDER,
'\0'
)
const request = transformRequest(url, server, { ssr }).catch((e) => {
transformRequest(url, server, { ssr }).catch((e) => {
if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP) {
// This are expected errors
return
}
// Unexpected error, log the issue but avoid an unhandled exception
config.logger.error(e.message)
})
if (depsOptimizer && !config.legacy?.devDepsScanner) {
depsOptimizer.delayDepsOptimizerUntil(id, () => request)
}
})
}

Expand Down
29 changes: 26 additions & 3 deletions packages/vite/src/node/server/transformRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '../utils'
import { checkPublicFile } from '../plugins/asset'
import { ssrTransform } from '../ssr/ssrTransform'
import { getDepsOptimizer } from '../optimizer'
import { injectSourcesContent } from './sourcemap'
import { isFileServingAllowed } from './middlewares/static'

Expand Down Expand Up @@ -118,9 +119,8 @@ async function doTransform(
) {
url = removeTimestampQuery(url)

const { config, pluginContainer, moduleGraph, watcher } = server
const { root, logger } = config
const prettyUrl = isDebug ? prettifyUrl(url, root) : ''
const { config, pluginContainer } = server
const prettyUrl = isDebug ? prettifyUrl(url, config.root) : ''
const ssr = !!options.ssr

const module = await server.moduleGraph.getModuleByUrl(url, ssr)
Expand All @@ -142,6 +142,29 @@ async function doTransform(
// resolve
const id =
(await pluginContainer.resolveId(url, undefined, { ssr }))?.id || url

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

const depsOptimizer = getDepsOptimizer(config)
if (depsOptimizer && !config.legacy?.devDepsScanner) {
depsOptimizer.delayDepsOptimizerUntil(id, () => result)
}

return result
}

async function loadAndTransform(
id: string,
url: string,
server: ViteDevServer,
options: TransformOptions,
timestamp: number
) {
const { config, pluginContainer, moduleGraph, watcher } = server
const { root, logger } = config
const prettyUrl = isDebug ? prettifyUrl(url, config.root) : ''
const ssr = !!options.ssr

const file = cleanUrl(id)

let code: string | null = null
Expand Down

0 comments on commit 2db1b5b

Please sign in to comment.