File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ export default defineConfig({
3232 react ( ) ,
3333 vitePluginUseCache ( ) ,
3434 vitePluginVirtualModuleTest ( ) ,
35+ testRscVirtualClientPackagePlugin ( ) ,
3536 rsc ( {
3637 entries : {
3738 client : './src/framework/entry.browser.tsx' ,
@@ -271,6 +272,25 @@ export default { fetch: handler };
271272 } ,
272273} ) as any
273274
275+ function testRscVirtualClientPackagePlugin ( ) : Plugin {
276+ return {
277+ name : 'test-rsc-virtual-client-package' ,
278+ enforce : 'pre' ,
279+ resolveId ( source , importer ) {
280+ // `rsc:virtual-client-package` should pass an explicit root importer.
281+ if (
282+ this . environment . name === 'rsc' &&
283+ source === '@vitejs/test-dep-transitive-client/client' &&
284+ importer == null
285+ ) {
286+ throw new Error (
287+ '`rsc:virtual-client-package` root resolution requires an importer' ,
288+ )
289+ }
290+ } ,
291+ }
292+ }
293+
274294function testBuildPlugin ( ) : Plugin [ ] {
275295 const moduleIds : { name : string ; ids : string [ ] } [ ] = [ ]
276296 return [
Original file line number Diff line number Diff line change @@ -1720,9 +1720,15 @@ function vitePluginUseClient(
17201720 // transitive dependency reachable from `importer` but not installed
17211721 // at the root (see #1247). In that case, skip virtualization and
17221722 // let it fall back to referencing the fully resolved module id.
1723+ // Vite's resolver already treats an undefined importer as the project
1724+ // root, but other plugins may not, so pass the root importer explicitly.
1725+ const rootImporter = path . join (
1726+ this . environment . config . root ,
1727+ 'index.html' ,
1728+ )
17231729 const resolvedAtRoot = await this . resolve (
17241730 source ,
1725- undefined ,
1731+ rootImporter ,
17261732 options ,
17271733 )
17281734 if ( ! resolvedAtRoot || resolvedAtRoot . id !== resolved . id ) {
You can’t perform that action at this time.
0 commit comments