@@ -1963,46 +1963,39 @@ export function __fix_cloudflare(): Plugin {
19631963function validateImportPlugin ( ) : Plugin {
19641964 return {
19651965 name : 'rsc:validate-imports' ,
1966- enforce : 'pre' ,
1967- async resolveId ( source , importer , options ) {
1968- // skip validation during optimizeDeps scan since for now
1969- // we want to allow going through server/client boundary loosely
1970- if ( isScanBuild || ( 'scan' in options && options . scan ) ) {
1971- return
1972- }
1966+ resolveId : {
1967+ order : 'pre' ,
1968+ async handler ( source , importer , options ) {
1969+ // optimizer is not aware of server/client boudnary so skip
1970+ if ( 'scan' in options && options . scan ) {
1971+ return
1972+ }
19731973
1974- // Validate client-only imports in server environments
1975- if (
1976- source === 'client-only' &&
1977- ( this . environment . name === 'rsc' || this . environment . name === 'ssr' )
1978- ) {
1979- // Allow client-only in client components during SSR builds
1980- if ( importer && this . environment . name === 'ssr' ) {
1981- try {
1982- const code = await this . load ( { id : importer } )
1983- if (
1984- code ?. code ?. includes ( '"use client"' ) ||
1985- code ?. code ?. includes ( "'use client'" )
1986- ) {
1987- return
1988- }
1989- } catch ( e ) {
1990- // If we can't load the importer, proceed with validation
1974+ // Validate client-only imports in server environments
1975+ if ( source === 'client-only' ) {
1976+ if ( this . environment . name === 'rsc' ) {
1977+ throw new Error (
1978+ `'client-only' cannot be imported in server build (importer: '${ importer ?? 'unknown' } ', environment: ${ this . environment . name } )` ,
1979+ )
19911980 }
1981+ return { id : `\0virtual:vite-rsc/empty` , moduleSideEffects : false }
1982+ }
1983+ if ( source === 'server-only' ) {
1984+ if ( this . environment . name !== 'rsc' ) {
1985+ throw new Error (
1986+ `'server-only' cannot be imported in client build (importer: '${ importer ?? 'unknown' } ', environment: ${ this . environment . name } )` ,
1987+ )
1988+ }
1989+ return { id : `\0virtual:vite-rsc/empty` , moduleSideEffects : false }
19921990 }
1993- throw new Error (
1994- `'client-only' is included in server build (importer: ${ importer ?? 'unknown' } )` ,
1995- )
1996- }
19971991
1998- // Validate server-only imports in client environment
1999- if ( source === 'server-only' && this . environment . name === 'client' ) {
2000- throw new Error (
2001- `'server-only' is included in client build (importer: ${ importer ?? 'unknown' } )` ,
2002- )
1992+ return
1993+ } ,
1994+ } ,
1995+ load ( id ) {
1996+ if ( id . startsWith ( '\0virtual:vite-rsc/empty' ) ) {
1997+ return `export {}`
20031998 }
2004-
2005- return
20061999 } ,
20072000 }
20082001}
0 commit comments