Skip to content

feat(pages): return typed results from page actions - #1057

Draft
hyfdev wants to merge 5 commits into
mainfrom
feat/page-action-result
Draft

hyfdev wants to merge 5 commits into
mainfrom
feat/page-action-result

Conversation

@hyfdev

@hyfdev hyfdev commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

An action can only refresh the page today, and the value it returns is dropped, so a preview or an inline save that needs a small answer reruns the loader and resends all page data.

Wrapping an action with definePageAction(handler, { reload: false }) now returns its value to action() as a typed result and skips the loader:

export const actions = {
  preview: definePageAction(defineHandler(() => ({ validRows: 3 })), { reload: false }),
};

const reply = await action('/imports?preview');
if (reply.ok) console.log(reply.result?.validRows);

The page, URL, history and scroll stay as they are.

Unwrapped actions, forms and island forms behave as before, and their responses are unchanged.

Each action() request names its target in a short header, and the server skips the loader only when that target matches the action it ran, so a redirect or rewrite falls back to the normal refresh.

Older clients and servers keep the current behavior.

Fixes #859

Keep React error recovery on the current page and release the shared router’s pending resource when a result-only action settles.

Update the action client and route declaration tests to cover the result callback and generated result type.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Cloudflare builds and deploys previews for this pull request. Learn more about Cloudflare previews.

Worker Status Deployment Commit
void-cloud Deployed Preview 1445cd2

Updated: Dec 6, 2026, 03:26 UTC | Dashboard

This branch has not been deployed

No deployments
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.

Allow page actions to return typed data without rerunning the loader

1 participant