Skip to content

fix(pages): keep the page query when an action re-renders the page - #769

Merged
cpojer merged 1 commit into
voidzero-dev:mainfrom
karthickeyan-dev:fix/action-preserve-query
Nov 10, 2026
Merged

cpojer merged 1 commit into
voidzero-dev:mainfrom
karthickeyan-dev:fix/action-preserve-query

Conversation

@karthickeyan-dev

Copy link
Copy Markdown
Contributor

Closes #751

Problem

After an action re-rendered the page, the page shown was the action URL minus its action key. An action posted as /items?vote from /items?page=2&search=foo re-ran the loader without page or search, changed the address bar to /items, reset scroll and pushed a history entry. 7a1a1ce fixed the typed ?name&key=value form; this covers the rest of the issue.

Changes

When action() or useForm (React, Vue, Svelte, Solid) posts to the current path, submitAction() adds the page's query after the action URL's own parameters:

// on /items?page=2&search=foo
await action('/items?vote'); // POST /items?vote&page=2&search=foo
  • The action and loader see the page query. The returned page URL then matches the current URL, so the existing scroll and history logic keeps both in place.
  • A key written in the action URL wins: action('/items?vote&page=1') posts with page=1.
  • The page's segments are appended verbatim, not re-encoded, so the URL comparison for scroll and history holds.
  • A non-GET Link and router.visit() are unchanged and still send the URL as given.

Redirects. Named-action c.redirect() merges the request query into the location. The client now names the segments it added in X-VoidPages-Preserved-Query, and redirectLocation() strips that suffix before merging. So the preserved query never follows a redirect, and c.redirect('/items') clears it. A query written in the action URL still merges as before. If the request query no longer ends with the named segments (for example after a rewrite with its own query), the header is ignored.

Behavior change: an app that relied on an action clearing the query should return c.redirect('/items'). There is no per-call opt-out.

Docs: new "Query parameters after submission" section in actions-and-forms.md, a note in rewrites.md, and a maintainer note in packages/void/AGENTS.md.

Verification

  • action-result.test.ts: merge cases (named and default actions, bare ?, key precedence, hash, other paths, encoded segments) and action() with params.
  • routing-runtime.test.ts: the preserved query is left out of default, 303, 307, middleware and rewrite redirects. It stays in the in-place page URL. A header that doesn't match the request query is ignored.
  • pages-client.test.ts: an in-place action from /editor?page=2&search=foo sends the merged URL and header, does not scroll or push, and replaces history with the same URL.
  • Shared browser contract: the action/form scroll test now starts on /scroll-restoration?page=2. After each in-place action it checks the URL, the loader's page and history.length, and that the redirect lands on ?redirected=1 without page=2. It passes in dev and preview for all four adapters. The playground loaders now expose page.
  • The new unit tests fail against the previous source.
  • Vue and Solid form unit tests run without a DOM, so they now stub window.location.
  • vp run check passes.
  • vp run test: 791 files, 16,600 passed, 37 skipped.

🤖 Generated with Claude Code

An action() or useForm submission that posts to the current path now adds
the page's query to the action URL, so the action and loader see it and the
URL, scroll and history entry stay as they are. Keys in the action URL win.

The client names the added segments in X-VoidPages-Preserved-Query, and
named-action c.redirect() leaves them out, so a redirect never inherits the
preserved query. c.redirect('/items') clears it.

Closes voidzero-dev#751

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cpojer cpojer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@cpojer
cpojer merged commit 72de291 into voidzero-dev:main Nov 10, 2026
2 checks passed
@karthickeyan-dev
karthickeyan-dev deleted the fix/action-preserve-query branch November 11, 2026 10:21
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.

Actions lose the page's query unless the caller adds it to the action URL by hand

2 participants