feat(runtime): execute Server Actions on Cloudflare - #41
Merged
Conversation
Server actions previously 500'd on every request: the runtime resolved the action via `mod[entry.export]`, but Next does NOT expose actions as named exports of the page module. Empirically verified (real Next 14.2 + 15.1 builds) that Next registers actions in a webpack worker module and resolves them the way this now does: mod.__next_app__.require(<moduleId>)[<actionId>] // the action function The return value is Flight-encoded via the module's own react-server-dom-webpack renderToReadableStream (`text/x-component`), which the Next client decodes. Both resolution and encoding are proven against real builds on Next 14 and 15, and handle the CJS→ESM interop (compiled module lands under import()'s `.default`). Side effects now run end-to-end: mutations, revalidatePath/revalidateTag, cookies, redirect(). Still partial (documented in CLOUDFLARE_PARITY.md): JS- invoked actions with bound args / Flight-encoded arg bodies, and full progressive-enhancement page re-render after an action (coupled to dynamic SSR). Adds unit + integration tests (resolveActionFn / encodeFlightReply / handleServerAction) covering both module shapes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ru3K1fyNRnyTXQ95Gmv6Su
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Server actions previously 500'd on every request — the runtime resolved them
via
mod[entry.export], but Next does not expose actions as named exports ofthe page module.
Verified empirically against real Next 14.2 and 15.1 builds that Next
registers actions in a webpack worker module and resolves them the way this now
does:
The return value is Flight-encoded via the module's own
react-server-dom-webpackrenderToReadableStream(text/x-component), whichthe Next client decodes. Both resolution and encoding are proven on Next 14 + 15,
including the CJS→ESM interop (compiled module lands under
import()'s.default).Works now: action side effects run end-to-end — mutations,
revalidatePath/revalidateTag, cookies,redirect(); the return value isFlight-encoded.
Still partial (documented in
CLOUDFLARE_PARITY.md): JS-invoked actions withbound args / Flight-encoded arg bodies, and full progressive-enhancement page
re-render after an action (coupled to the dynamic-SSR gap).
Adds unit + integration tests (
resolveActionFn/encodeFlightReply/handleServerAction) over both module shapes.🤖 Generated with Claude Code
https://claude.ai/code/session_01Ru3K1fyNRnyTXQ95Gmv6Su