File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed
examples/basic/src/routes Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,13 @@ function defineTest(f: Fixture) {
244244 await page . getByRole ( 'button' , { name : 'client-counter: 1' } ) . click ( )
245245 } )
246246
247+ test ( 'import environment' , async ( { page } ) => {
248+ await page . goto ( f . url ( ) )
249+ await expect ( page . getByTestId ( 'import-environment' ) ) . toHaveText (
250+ '[test-import-environment: test-ssr]' ,
251+ )
252+ } )
253+
247254 test ( 'server action @js' , async ( { page } ) => {
248255 await page . goto ( f . url ( ) )
249256 await waitForHydration ( page )
Original file line number Diff line number Diff line change 1+ export 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 ( )
7+ return (
8+ < div data-testid = "import-environment" >
9+ [test-import-environment:{ ' ' }
10+ < span dangerouslySetInnerHTML = { { __html : html } } /> ]
11+ </ div >
12+ )
13+ }
Original file line number Diff line number Diff line change 1+ import { useState } from 'react'
2+ import { renderToString } from 'react-dom/server'
3+
4+ // SSR-only: useState and renderToString are not available in RSC environment
5+
6+ function ClientComponent ( ) {
7+ const [ state ] = useState ( 'test-ssr' )
8+ return < span > { state } </ span >
9+ }
10+
11+ export function testSsrModule ( ) : string {
12+ return renderToString ( < ClientComponent /> )
13+ }
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import { TestHmrSharedServer } from './hmr-shared/server'
3434import { TestHmrSwitchClient } from './hmr-switch/client'
3535import { TestHmrSwitchServer } from './hmr-switch/server'
3636import { TestHydrationMismatch } from './hydration-mismatch/server'
37+ import { TestImportEnvironment } from './import-environment/server'
3738import { TestImportMetaGlob } from './import-meta-glob/server'
3839import { TestLazyCssClientToClient } from './lazy-css/client-to-client'
3940import { TestLazyCssServerToClient } from './lazy-css/server-to-client'
@@ -111,6 +112,7 @@ export function Root(props: { url: URL }) {
111112 < TestReactCache url = { props . url } />
112113 < TestCssQueries />
113114 < TestImportMetaGlob />
115+ < TestImportEnvironment />
114116 < TestAssetsServer />
115117 < TestTreeShakeServer />
116118 < TestTreeShake2 />
You can’t perform that action at this time.
0 commit comments