Skip to content

Commit e539c58

Browse files
committed
fix(rsc): avoid dev server access during builds
1 parent d426ce7 commit e539c58

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

packages/plugin-rsc/src/plugins/server-function-directives.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ export async function getData() {
124124
).toEqual([expect.stringMatching(/^\$\$hoist_/)])
125125
})
126126

127+
it('does not require a dev server during build transforms', async () => {
128+
const { manager, run } = createHarness([cacheDirective()])
129+
manager.server = undefined as unknown as Manager['server']
130+
await expect(
131+
run(`export async function getData() { "use cache"; return 1 }`),
132+
).resolves.toBeDefined()
133+
})
134+
127135
it('encrypts captured values without adding ciphertext to the wrapper', async () => {
128136
const wrap = vi.fn(({ value }: { value: string }) => `cache(${value})`)
129137
const { run } = createHarness([cacheDirective({ wrap })])

packages/plugin-rsc/src/plugins/server-function-directives.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ export function vitePluginServerFunctionDirectives(options: Options): Plugin {
176176
const useServerBoundary = hasDirective(ast.body, 'use server')
177177
if (!isServer && useServerBoundary) return
178178

179-
const serverEnvironment =
180-
manager.server.environments[options.serverEnvironmentName]
181179
let normalizedId: string
182180
if (manager.config.command === 'build') {
183181
normalizedId = hashString(manager.toRelativeId(id))
184182
} else {
183+
const serverEnvironment =
184+
manager.server.environments[options.serverEnvironmentName]
185185
if (!serverEnvironment) {
186186
throw new Error(
187187
`Missing ${JSON.stringify(options.serverEnvironmentName)} environment`,

0 commit comments

Comments
 (0)