Skip to content
Draft
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ac2325a
feat(rsc): generalize server function transforms
james-elicx Jun 11, 2026
142fb07
feat(rsc): support custom server function directives
james-elicx Jun 11, 2026
223b164
fix(rsc): validate custom server directives
james-elicx Jun 11, 2026
d426ce7
feat(rsc): expose server function parameter metadata
james-elicx Jun 11, 2026
e539c58
fix(rsc): avoid dev server access during builds
james-elicx Jun 12, 2026
35b052c
Apply suggestion from @james-elicx
james-elicx Jun 12, 2026
49a0575
Merge branch 'main' into codex/server-function-directives
james-elicx Jun 12, 2026
c217ebc
feat(rsc): configure module directive async validation
james-elicx Jun 12, 2026
8595871
feat(rsc): import custom directive runtimes
james-elicx Jun 12, 2026
76f1d41
fix(rsc): expose wrapped directive hoists
james-elicx Jun 12, 2026
2ae42d1
feat(rsc): preserve decoded server references
james-elicx Jun 12, 2026
06e5841
fix(rsc): preserve custom directive references
james-elicx Jun 12, 2026
82d2c57
fix(rsc): deduplicate server reference exports
james-elicx Jun 12, 2026
8b82c9c
Merge remote-tracking branch 'upstream/main' into codex/server-functi…
james-elicx Jul 20, 2026
5a2fd75
refactor(rsc): keep custom directives external
james-elicx Jul 20, 2026
81caa6b
Merge remote-tracking branch 'upstream/main' into codex/server-functi…
james-elicx Jul 24, 2026
18fd2c0
refactor(rsc): align transform primitives with server claims
james-elicx Jul 24, 2026
50eaf47
refactor(rsc): remove non-split transform leftovers
james-elicx Jul 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions packages/plugin-rsc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ import {
withResolvedIdProxy,
} from './plugins/resolved-id-proxy'
import { scanBuildStripPlugin } from './plugins/scan'
import {
SERVER_FUNCTION_DIRECTIVE_MARKER,
type ServerFunctionDirective,
type ServerFunctionDirectiveContext,
vitePluginServerFunctionDirectives,
} from './plugins/server-function-directives'
import {
parseCssVirtual,
toCssVirtual,
Expand Down Expand Up @@ -171,6 +177,8 @@ class RscPluginManager {
}

export type RscPluginOptions = {
/** @experimental */
serverFunctionDirectives?: ServerFunctionDirective[]
/**
* shorthand for configuring `environments.(name).build.rollupOptions.input.index`
*/
Expand Down Expand Up @@ -283,6 +291,8 @@ export type RscPluginOptions = {
customClientEntry?: boolean
}

export type { ServerFunctionDirective, ServerFunctionDirectiveContext }

export type PluginApi = {
manager: RscPluginManager
}
Expand Down Expand Up @@ -339,6 +349,30 @@ export function vitePluginRscMinimal(
},
...vitePluginRscCore(),
...vitePluginUseClient(rscPluginOptions, manager),
...(rscPluginOptions.serverFunctionDirectives?.length
? [
vitePluginServerFunctionDirectives({
definitions: rscPluginOptions.serverFunctionDirectives,
manager,
serverEnvironmentName: rscPluginOptions.environment?.rsc ?? 'rsc',
browserEnvironmentName:
rscPluginOptions.environment?.browser ?? 'client',
rscRuntime: resolvePackage(`${PKG_NAME}/react/rsc`),
ssrRuntime: resolvePackage(`${PKG_NAME}/react/ssr`),
browserRuntime: resolvePackage(`${PKG_NAME}/react/browser`),
encryptionRuntime: resolvePackage(
`${PKG_NAME}/utils/encryption-runtime`,
),
expandExportAll: (context, code, ast, id) =>
transformExpandExportAll({
code,
ast,
importer: id,
...createTransformExpandExportAllContext(context),
}),
}),
]
: []),
...vitePluginUseServer(rscPluginOptions, manager),
...vitePluginDefineEncryptionKey(rscPluginOptions),
{
Expand Down Expand Up @@ -1946,7 +1980,9 @@ function vitePluginUseServer(
// filter: { code: 'use server' },
async handler(code, id) {
if (!code.includes('use server')) {
delete manager.serverReferenceMetaMap[id]
if (!code.includes(SERVER_FUNCTION_DIRECTIVE_MARKER)) {
delete manager.serverReferenceMetaMap[id]
}
return
}
let ast = await parseAstAsync(code)
Expand Down Expand Up @@ -2017,11 +2053,15 @@ function vitePluginUseServer(
delete manager.serverReferenceMetaMap[id]
return
}
const customExportNames =
manager.serverReferenceMetaMap[id]?.exportNames ?? []
manager.serverReferenceMetaMap[id] = {
importId: id,
referenceKey: getNormalizedId(),
exportNames:
'names' in result ? result.names : result.exportNames,
exportNames: [
...customExportNames,
...('names' in result ? result.names : result.exportNames),
],
}
const importSource = resolvePackage(`${PKG_NAME}/react/rsc`)
output.prepend(
Expand Down
Loading
Loading