Skip to content

Commit 3798dc9

Browse files
committed
refactor: expose environment.browser option
1 parent 7975e6d commit 3798dc9

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

packages/plugin-rsc/examples/browser-mode/vite.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ export default defineConfig({
1313
vitePluginRscMinimal(),
1414
vitePluginUseClient({
1515
environment: {
16-
serverEnvironmentName: 'client',
16+
rsc: 'client',
17+
browser: 'react_client',
1718
},
1819
}),
1920
vitePluginUseServer({
2021
environment: {
21-
serverEnvironmentName: 'client',
22+
rsc: 'client',
23+
browser: 'react_client',
2224
},
2325
}),
2426
vitePluginDefineEncryptionKey({
2527
environment: {
26-
serverEnvironmentName: 'client',
28+
rsc: 'client',
29+
browser: 'react_client',
2730
},
2831
}),
2932
{

packages/plugin-rsc/src/plugin.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ export type RscPluginOptions = {
135135
/**
136136
* Custom environment configuration
137137
* @experimental
138-
* @default { serverEnvironmentName: 'rsc' }
138+
* @default { browser: 'client', ssr: 'ssr', rsc: 'rsc' }
139139
*/
140140
environment?: {
141-
serverEnvironmentName?: string
141+
browser?: string
142+
ssr?: string
143+
rsc?: string
142144
}
143145
}
144146

@@ -974,8 +976,7 @@ export function vitePluginUseClient(
974976
// https://github.com/vitejs/vite/blob/4bcf45863b5f46aa2b41f261283d08f12d3e8675/packages/vite/src/node/utils.ts#L175
975977
const bareImportRE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/
976978

977-
const serverEnvironmentName =
978-
useClientPluginOptions.environment?.serverEnvironmentName ?? 'rsc'
979+
const serverEnvironmentName = useClientPluginOptions.environment?.rsc ?? 'rsc'
979980

980981
return [
981982
{
@@ -1183,8 +1184,7 @@ export function vitePluginDefineEncryptionKey(
11831184
const KEY_PLACEHOLDER = '__vite_rsc_define_encryption_key'
11841185
const KEY_FILE = '__vite_rsc_encryption_key.js'
11851186

1186-
const serverEnvironmentName =
1187-
useServerPluginOptions.environment?.serverEnvironmentName ?? 'rsc'
1187+
const serverEnvironmentName = useServerPluginOptions.environment?.rsc ?? 'rsc'
11881188

11891189
return [
11901190
{
@@ -1244,8 +1244,9 @@ export function vitePluginUseServer(
12441244
'ignoredPackageWarnings' | 'enableActionEncryption' | 'environment'
12451245
>,
12461246
): Plugin[] {
1247-
const serverEnvironmentName =
1248-
useServerPluginOptions.environment?.serverEnvironmentName ?? 'rsc'
1247+
const serverEnvironmentName = useServerPluginOptions.environment?.rsc ?? 'rsc'
1248+
const browserEnvironmentName =
1249+
useServerPluginOptions.environment?.browser ?? 'browser'
12491250

12501251
return [
12511252
{
@@ -1341,8 +1342,8 @@ export function vitePluginUseServer(
13411342
const output = result?.output
13421343
if (!output?.hasChanged()) return
13431344
serverReferences[getNormalizedId()] = id
1344-
// TODO
1345-
const name = this.environment.name === 'ssr' ? 'ssr' : 'browser'
1345+
const name =
1346+
this.environment.name === browserEnvironmentName ? 'browser' : 'ssr'
13461347
const importSource = resolvePackage(`${PKG_NAME}/react/${name}`)
13471348
output.prepend(`import * as $$ReactClient from "${importSource}";\n`)
13481349
return {

0 commit comments

Comments
 (0)