Skip to content

Commit 07adbab

Browse files
committed
feat(rsc): add import(.., { environment: ... })
1 parent f9e79eb commit 07adbab

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

packages/plugin-rsc/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,18 @@ ssrModule.renderHTML(...);
245245
export function renderHTML(...) {}
246246
```
247247

248+
#### `import.meta.viteRsc.import(..., { environment: ... })`
249+
250+
TODO
251+
252+
```ts
253+
const ssrModule = await import.meta.viteRsc.import(
254+
"./entry.ssr.tsx",
255+
{ with: { environment: "ssr" } }
256+
)
257+
ssrModule.renderHTML(...);
258+
```
259+
248260
### Available on `rsc` environment
249261

250262
#### `import.meta.viteRsc.loadCss`

packages/plugin-rsc/examples/basic/src/framework/entry.rsc.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ async function handleRequest({
9191
})
9292
}
9393

94+
// TODO: implement this
95+
import.meta.viteRsc.import<typeof import('./entry.ssr.tsx')>('./entry.ssr', {
96+
environment: 'ssr',
97+
})
98+
// import.meta.viteRsc.importEnvironment(import("./entry.ssr.tsx"));
99+
// import.meta.viteRsc.importAsset(import("./entry.browser.tsx"));
100+
// import(String("test"), { with: { viteRsc: "environment:ssr" } });
101+
// import(String("test"), { with: { viteRsc: "asset:client" } });
102+
// import("./entry.ssr.tsx", { with: { viteRscEnvironment: "rsc" } });
103+
94104
// Delegate to SSR environment for html rendering.
95105
// The plugin provides `loadModule` helper to allow loading SSR environment entry module
96106
// in RSC environment. however this can be customized by implementing own runtime communication

packages/plugin-rsc/types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ declare global {
44
loadCss: (importer?: string) => import('react').ReactNode
55
loadModule: <T>(environmentName: string, entryName?: string) => Promise<T>
66
loadBootstrapScriptContent: (entryName: string) => Promise<string>
7+
8+
// TODO: loadModule alternative
9+
import: <T>(specifier, attributes: { environment: string }) => Promise<T>
10+
11+
// TODO: loadBootstrapScriptContent alternative?
12+
// import: (specifier, attributes: { asset: string }) => Promise<string>
713
}
814
}
915

0 commit comments

Comments
 (0)