@@ -32,7 +32,11 @@ import {
32
32
} from './transforms'
33
33
import { generateEncryptionKey , toBase64 } from './utils/encryption-utils'
34
34
import { createRpcServer } from './utils/rpc'
35
- import { normalizeViteImportAnalysisUrl , prepareError } from './vite-utils'
35
+ import {
36
+ cleanUrl ,
37
+ normalizeViteImportAnalysisUrl ,
38
+ prepareError ,
39
+ } from './vite-utils'
36
40
import { cjsModuleRunnerPlugin } from './plugins/cjs'
37
41
import { evalValue , parseIdQuery } from './plugins/utils'
38
42
@@ -959,9 +963,12 @@ function vitePluginUseClient(
959
963
let importId : string
960
964
let referenceKey : string
961
965
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
965
972
// created by a package imported on server environment, which breaks the
966
973
// expectation on dependency optimizer on browser. Directly copying over
967
974
// "?v=<hash>" from client optimizer in client reference can make a hashed
@@ -978,9 +985,7 @@ function vitePluginUseClient(
978
985
`[vite-rsc] detected an internal client boundary created by a package imported on rsc environment` ,
979
986
)
980
987
}
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 ) ) } `
984
989
referenceKey = importId
985
990
} else if ( packageSource ) {
986
991
if ( this . environment . mode === 'dev' ) {
@@ -1223,8 +1228,10 @@ function vitePluginUseServer(
1223
1228
let normalizedId_ : string | undefined
1224
1229
const getNormalizedId = ( ) => {
1225
1230
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
+ ) {
1228
1235
const ignored =
1229
1236
useServerPluginOptions . ignoredPackageWarnings ?. some (
1230
1237
( pattern ) =>
@@ -1238,8 +1245,8 @@ function vitePluginUseServer(
1238
1245
)
1239
1246
}
1240
1247
// 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 )
1243
1250
}
1244
1251
if ( config . command === 'build' ) {
1245
1252
normalizedId_ = hashString ( path . relative ( config . root , id ) )
0 commit comments