Skip to content

Allow page actions to return typed data without rerunning the loader #859

Open

Description

@karthickeyan-dev

Request

Allow the page-action client to receive an action's own typed result without automatically fetching and rendering the page loader's data again.

Two examples:

  • An import preview should return validation results for a confirmation dialog.
  • Saving question progress or reporting a question should return an acknowledgement without resending the question list.

Today, ordinary action returns refresh the page data instead. An explicit JSON response works for a raw HTTP caller, but it does not provide the same result through action().

Tested versions

  • Void 1.9.1
  • @void/react 1.9.1
  • React 19.3.1
  • Node 26.13.1

Reproduced in an isolated local Void/React project with a headless Chromium browser. Current upstream main has not been tested.

Minimal reproduction

Use this page companion:

// pages/index.server.ts
import { defineHandler } from "void";

let loaderCalls = 0;
let actionCalls = 0;

export const loader = defineHandler(() => ({
  loaderCalls: ++loaderCalls,
  actionCalls,
}));

export const actions = {
  save: defineHandler(() => {
    actionCalls++;
  }),
  preview: defineHandler(() => {
    actionCalls++;
    return { previewMarker: "action-only-result" };
  }),
  json: defineHandler((c) => {
    actionCalls++;
    return c.json({ previewMarker: "json-action-result" });
  }),
};

Render loaderCalls and actionCalls in the page. From a button handler, call each named action with the React helper and display the resolved result in component state:

import { action } from "@void/react";

const result = await action("/?preview", { data: {} });

Repeat with /?save and /?json. The counters are only local reproduction instrumentation, not persistent application state.

Observed results

Action return Call method Result
Nothing action("/?save", ...) Action runs once; loader runs once more. The promise resolves with { ok: true, pageData: ... }.
Plain object action("/?preview", ...) Action runs once; loader runs once more. The promise resolves with refreshed page data, without previewMarker.
c.json(...) Raw HTTP POST HTTP 200 with { previewMarker: "json-action-result" }. Independent data can be returned at the HTTP boundary.
c.json(...) action("/?json", ...) Browser performs a full document navigation. The subsequent page load runs the loader, and the component's stored result resets to null.

For the plain-object case, the browser received:

{
  "ok": true,
  "pageData": {
    "component": "index",
    "props": { "loaderCalls": 4, "actionCalls": 2 },
    "params": {},
    "shared": {},
    "url": "/",
    "errors": null
  }
}

The preceding void-returning action changed the counters from (2, 0) to (3, 1); the plain-object action then changed them to (4, 2). Neither call returned the preview marker.

Desired behavior

Provide an opt-in mode where:

  • A serializable action result is available to the client with an inferred TypeScript type.
  • The page loader is not rerun automatically.
  • Existing middleware, authentication, validation and error handling still apply.
  • Applications can explicitly refresh page data when needed.
  • Existing actions retain their current reload behavior by default.

The exact API is open to maintainer guidance. This is a feature request for the page-action client; the JSON-response case is included to clarify why returning a Response does not currently provide that workflow.

Current workaround

Use an authenticated API route with a direct client request for previews or mutations that need independent results. This avoids the page refresh, but requires a separate endpoint and client request handling.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions