@@ -32,7 +32,11 @@ import {
3232} from './transforms'
3333import { generateEncryptionKey , toBase64 } from './utils/encryption-utils'
3434import { createRpcServer } from './utils/rpc'
35- import { normalizeViteImportAnalysisUrl , prepareError } from './vite-utils'
35+ import {
36+ cleanUrl ,
37+ normalizeViteImportAnalysisUrl ,
38+ prepareError ,
39+ } from './vite-utils'
3640import { cjsModuleRunnerPlugin } from './plugins/cjs'
3741import { evalValue , parseIdQuery } from './plugins/utils'
3842
@@ -959,9 +963,12 @@ function vitePluginUseClient(
959963 let importId : string
960964 let referenceKey : string
961965 const packageSource = packageSources . get ( id )
962- if ( ! packageSource && id . includes ( '?v=' ) ) {
963- assert ( this . environment . mode === 'dev' )
964- // If non package source `?v=<hash>` reached here, this is a client boundary
966+ if (
967+ ! packageSource &&
968+ this . environment . mode === 'dev' &&
969+ id . includes ( '/node_modules/' )
970+ ) {
971+ // If non package source reached here (often with ?v=... query), this is a client boundary
965972 // created by a package imported on server environment, which breaks the
966973 // expectation on dependency optimizer on browser. Directly copying over
967974 // "?v=<hash>" from client optimizer in client reference can make a hashed
@@ -978,9 +985,7 @@ function vitePluginUseClient(
978985 `[vite-rsc] detected an internal client boundary created by a package imported on rsc environment` ,
979986 )
980987 }
981- importId = `/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/${ encodeURIComponent (
982- id . split ( '?v=' ) [ 0 ] ! ,
983- ) } `
988+ importId = `/@id/__x00__virtual:vite-rsc/client-in-server-package-proxy/${ encodeURIComponent ( cleanUrl ( id ) ) } `
984989 referenceKey = importId
985990 } else if ( packageSource ) {
986991 if ( this . environment . mode === 'dev' ) {
@@ -1223,8 +1228,10 @@ function vitePluginUseServer(
12231228 let normalizedId_ : string | undefined
12241229 const getNormalizedId = ( ) => {
12251230 if ( ! normalizedId_ ) {
1226- if ( id . includes ( '?v=' ) ) {
1227- assert ( this . environment . mode === 'dev' )
1231+ if (
1232+ this . environment . mode === 'dev' &&
1233+ id . includes ( '/node_modules/' )
1234+ ) {
12281235 const ignored =
12291236 useServerPluginOptions . ignoredPackageWarnings ?. some (
12301237 ( pattern ) =>
@@ -1238,8 +1245,8 @@ function vitePluginUseServer(
12381245 )
12391246 }
12401247 // module runner has additional resolution step and it's not strict about
1241- // module identity of `import(id)` like browser, so we simply strip it off .
1242- id = id . split ( '?v=' ) [ 0 ] !
1248+ // module identity of `import(id)` like browser, so we simply strip queries such as `?v=` .
1249+ id = cleanUrl ( id )
12431250 }
12441251 if ( config . command === 'build' ) {
12451252 normalizedId_ = hashString ( path . relative ( config . root , id ) )
0 commit comments