From 0cb4b2550fa44a1c7bf5e37c70d7654627ea840e Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Fri, 15 Jul 2022 02:26:12 +0900 Subject: [PATCH] fix(ssr): strip NULL_BYTE_PLACEHOLDER before import --- packages/vite/src/node/plugins/importAnalysis.ts | 8 +------- packages/vite/src/node/ssr/ssrModuleLoader.ts | 4 ++-- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index f04cb8625f864b..27b9d274ff11b4 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -38,11 +38,9 @@ import { moduleListContains, normalizePath, prettifyUrl, - removeImportQuery, stripBomTag, timeFrom, - transformStableResult, - unwrapId + transformStableResult } from '../utils' import type { ResolvedConfig } from '../config' import type { Plugin } from '../plugin' @@ -706,10 +704,6 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin { // by the deps optimizer if (config.server.preTransformRequests && staticImportedUrls.size) { staticImportedUrls.forEach(({ url, id }) => { - url = unwrapId(removeImportQuery(url)).replace( - NULL_BYTE_PLACEHOLDER, - '\0' - ) transformRequest(url, server, { ssr }).catch((e) => { if (e?.code === ERR_OUTDATED_OPTIMIZED_DEP) { // This are expected errors diff --git a/packages/vite/src/node/ssr/ssrModuleLoader.ts b/packages/vite/src/node/ssr/ssrModuleLoader.ts index a2e30b2a6ccf5e..117682f762ad58 100644 --- a/packages/vite/src/node/ssr/ssrModuleLoader.ts +++ b/packages/vite/src/node/ssr/ssrModuleLoader.ts @@ -38,7 +38,7 @@ export async function ssrLoadModule( urlStack: string[] = [], fixStacktrace?: boolean ): Promise { - url = unwrapId(url).replace(NULL_BYTE_PLACEHOLDER, '\0') + url = unwrapId(url) // when we instantiate multiple dependency modules in parallel, they may // point to shared modules. We need to avoid duplicate instantiation attempts @@ -137,7 +137,7 @@ async function instantiateModule( if (dep[0] !== '.' && dep[0] !== '/') { return nodeImport(dep, mod.file!, resolveOptions) } - dep = unwrapId(dep) + dep = unwrapId(dep).replace(NULL_BYTE_PLACEHOLDER, '\0') if (!isCircular(dep) && !pendingImports.get(dep)?.some(isCircular)) { pendingDeps.push(dep) if (pendingDeps.length === 1) {