@@ -15,9 +15,7 @@ import {
1515 CLIENT_DIR ,
1616 CLIENT_PUBLIC_PATH ,
1717 DEP_VERSION_RE ,
18- FS_PREFIX ,
19- NULL_BYTE_PLACEHOLDER ,
20- VALID_ID_PREFIX
18+ FS_PREFIX
2119} from '../constants'
2220import {
2321 debugHmr ,
@@ -42,7 +40,8 @@ import {
4240 stripBomTag ,
4341 timeFrom ,
4442 transformStableResult ,
45- unwrapId
43+ unwrapId ,
44+ wrapId
4645} from '../utils'
4746import type { ResolvedConfig } from '../config'
4847import type { Plugin } from '../plugin'
@@ -330,8 +329,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
330329 // prefix it to make it valid. We will strip this before feeding it
331330 // back into the transform pipeline
332331 if ( ! url . startsWith ( '.' ) && ! url . startsWith ( '/' ) ) {
333- url =
334- VALID_ID_PREFIX + resolved . id . replace ( '\0' , NULL_BYTE_PLACEHOLDER )
332+ url = wrapId ( resolved . id )
335333 }
336334
337335 // make the URL browser-valid if not SSR
@@ -361,7 +359,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
361359 try {
362360 // delay setting `isSelfAccepting` until the file is actually used (#7870)
363361 const depModule = await moduleGraph . ensureEntryFromUrl (
364- url ,
362+ unwrapId ( url ) ,
365363 ssr ,
366364 canSkipImportAnalysis ( url )
367365 )
@@ -536,9 +534,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
536534 }
537535
538536 // record for HMR import chain analysis
539- // make sure to normalize away base
540- const urlWithoutBase = url . replace ( base , '/' )
541- importedUrls . add ( urlWithoutBase )
537+ // make sure to unwrap and normalize away base
538+ const hmrUrl = unwrapId ( url . replace ( base , '/' ) )
539+ importedUrls . add ( hmrUrl )
542540
543541 if ( enablePartialAccept && importedBindings ) {
544542 extractImportedBindings (
@@ -551,7 +549,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
551549
552550 if ( ! isDynamicImport ) {
553551 // for pre-transforming
554- staticImportedUrls . add ( { url : urlWithoutBase , id : resolvedId } )
552+ staticImportedUrls . add ( { url : hmrUrl , id : resolvedId } )
555553 }
556554 } else if ( ! importer . startsWith ( clientDir ) ) {
557555 if ( ! importer . includes ( 'node_modules' ) ) {
@@ -712,10 +710,7 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
712710 // by the deps optimizer
713711 if ( config . server . preTransformRequests && staticImportedUrls . size ) {
714712 staticImportedUrls . forEach ( ( { url, id } ) => {
715- url = unwrapId ( removeImportQuery ( url ) ) . replace (
716- NULL_BYTE_PLACEHOLDER ,
717- '\0'
718- )
713+ url = removeImportQuery ( url )
719714 transformRequest ( url , server , { ssr } ) . catch ( ( e ) => {
720715 if ( e ?. code === ERR_OUTDATED_OPTIMIZED_DEP ) {
721716 // This are expected errors
0 commit comments