Skip to content

feat(runtime): execute Server Actions on Cloudflare - #41

Merged
aynaash merged 1 commit into
mainfrom
feat/server-action-execution
Jul 3, 2026
Merged

feat(runtime): execute Server Actions on Cloudflare#41
aynaash merged 1 commit into
mainfrom
feat/server-action-execution

Conversation

@aynaash

@aynaash aynaash commented Jul 3, 2026

Copy link
Copy Markdown
Owner

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 of
the 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:

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 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 is
Flight-encoded.

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 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

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
@aynaash
aynaash merged commit 27d72db into main Jul 3, 2026
14 checks passed
@aynaash
aynaash deleted the feat/server-action-execution branch July 3, 2026 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant