File tree Expand file tree Collapse file tree 4 files changed +18
-10
lines changed
examples/basic/src/routes/import-environment Expand file tree Collapse file tree 4 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -247,7 +247,7 @@ function defineTest(f: Fixture) {
247247 test ( 'import environment' , async ( { page } ) => {
248248 await page . goto ( f . url ( ) )
249249 await expect ( page . getByTestId ( 'import-environment' ) ) . toHaveText (
250- '[test-import-environment: test-ssr]' ,
250+ '[test-import-environment: test-ssr-module: test-rsc-module ]' ,
251251 )
252252 } )
253253
Original file line number Diff line number Diff line change 1+ export const testRscModule = async ( ) => 'test-rsc-module'
Original file line number Diff line number Diff line change 11export async function TestImportEnvironment ( ) {
2- const ssr = await import . meta. viteRsc . import < typeof import ( './ssr' ) > (
3- './ssr.tsx' ,
4- { environment : 'ssr' } ,
5- )
6- const html = ssr . testSsrModule ( )
2+ const { testSsrModule } = await import . meta. viteRsc . import <
3+ typeof import ( './ssr' )
4+ > ( './ssr.tsx' , { environment : 'ssr' } )
5+ const html = await testSsrModule ( )
76 return (
87 < div data-testid = "import-environment" >
98 [test-import-environment:{ ' ' }
Original file line number Diff line number Diff line change @@ -4,10 +4,18 @@ import { renderToString } from 'react-dom/server'
44// SSR-only: useState and renderToString are not available in RSC environment
55
66function ClientComponent ( ) {
7- const [ state ] = useState ( 'test-ssr' )
8- return < span > { state } </ span >
7+ const [ state ] = useState ( 'test-ssr-module ' )
8+ return < > { state } </ >
99}
1010
11- export function testSsrModule ( ) : string {
12- return renderToString ( < ClientComponent /> )
11+ export async function testSsrModule ( ) {
12+ const { testRscModule } = await import . meta. viteRsc . import <
13+ typeof import ( './rsc' )
14+ > ( './rsc.tsx' , { environment : 'rsc' } )
15+ const value = await testRscModule ( )
16+ return renderToString (
17+ < >
18+ < ClientComponent /> : { value }
19+ </ > ,
20+ )
1321}
You can’t perform that action at this time.
0 commit comments