refactor(use-cache): move server function directives to user land#2156
refactor(use-cache): move server function directives to user land#2156james-elicx wants to merge 8 commits into
Conversation
commit: |
|
|
/bigbonk review for issues |
|
/bigbonk review for issues |
|
|
Review posted to PR #2156. SummaryI reviewed PR #2156 (userland server-function directives). After installing the pinned prerelease via a frozen Key findings (none blocking):
Positive verification: I also flagged an environment gotcha: with a stale |
|
I've added a support of user land server reference registration via vitejs/vite-plugin-react#1310, which is expected to simplify manual server reference management from use cache transform plugin here. |
Summary
POC for implementing server-function directives entirely in vinext user land instead of adding the
serverFunctionDirectivesoption and orchestration plugin originally proposed in vitejs/vite-plugin-react#1246.This update pins
@vitejs/plugin-rscto the latest #1246 prerelease at50eaf476, which incorporates the merged server-reference registration API from vitejs/vite-plugin-react#1310.vinext initand deploy-time dependency installation also use that exact prerelease because the registry's stable0.5.30package predates #1310 despite sharing the same package version. This PR remains stacked on #1871.Vinext-owned lifecycle
Vinext now uses a single
vinext:server-function-directivesplugin beforersc:use-server. Running first preserves the original module shape for mixed module-level"use server"boundaries, while #1310's independently owned claims let the two plugins update metadata without an after-plugin restoration pass.The plugin uses
RscPluginManager.serverReferencesto:resolve()for plugin-rsc's canonical development and build reference identityreplaceClaim()for references emitted by vinextdeleteClaim()when a directive is removed or another environment does not own the referencevinext:server-function-directivesandrsc:use-serverduring HMRAs a result, vinext no longer needs:
rsc:use-serverserverReferenceMetaMapThe private
/* __vinext_server_function_directives__ */marker remains only to avoid reprocessing vinext's own transformed output; plugin-rsc does not interpret it.Transform composition
Vinext composes the public low-level primitives directly:
transformWrapExport()for module-level custom directivestransformHoistInlineDirective()for function-level custom directivestransformDirectiveProxyExport()for SSR/client proxiestransformExpandExportAll()for module-level re-exportsGenerated RSC transforms import
registerServerReferencefrom@vitejs/plugin-rsc/react/rsc/server.Cache replay API
Cached Flight replay continues to use the API merged in vitejs/vite-plugin-react#1289:
This preserves opaque server references while replaying cached RSC without importing their implementation into the replaying RSC runtime.
Upstream dependencies
This POC now depends on:
max-widthmedia-query syntax #1310's publicserverReferences.resolve(),replaceClaim(), anddeleteClaim()APIspreserveServerReferencescache replay supportgetPluginApi()access toRscPluginManagerIt does not depend on:
serverFunctionDirectivesplugin optionrsc:use-serverValidation
"use cache"→"use server"→"use cache"Refs #1871