Skip to content

Preserve search parameters in remote form actions#16373

Open
tianrking wants to merge 1 commit into
sveltejs:version-3from
tianrking:agent/preserve-search-params-in-remote-forms
Open

Preserve search parameters in remote form actions#16373
tianrking wants to merge 1 commit into
sveltejs:version-3from
tianrking:agent/preserve-search-params-in-remote-forms

Conversation

@tianrking

Copy link
Copy Markdown

closes #16363

Remote form actions were generated as ?/remote=..., so a native form submission replaced the page's existing query string. Generate the action from the current search parameters instead, then set the internal /remote parameter.

This keeps user-visible parameters such as pagination when JavaScript is disabled, and keeps the client-generated action aligned with the server-generated one.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Additional validation:

  • pnpm --dir packages/kit/test/apps/async exec playwright test test.js --grep 'form works' (Chromium with and without JavaScript)
  • pnpm -F @sveltejs/kit prepublishOnly

Changesets

  • Added a patch changeset for @sveltejs/kit.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from fce4c63:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/fce4c631e93b643627c4ff46cc219c794d88e0a7

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16373

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fce4c63

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

get: () => `?/remote=${__.id}`,
get: () => {
const search = new URLSearchParams(get_request_store().event.url.search);
search.set('/remote', __.id);

@teemingc teemingc Jul 18, 2026

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.

This encodes the / in /remote which causes the tests to fail. We need to add it without setting it on URLSearchParams to avoid encoding it both here and on the client.

const action_id_without_key = id;
const action_id = id + (key != undefined ? `/${JSON.stringify(key)}` : '');
const action = '?/remote=' + encodeURIComponent(action_id);
const search = new URLSearchParams(location.search);

@teemingc teemingc Jul 18, 2026

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.

This serialises the search params of the page when the instance is created but we should do it only when it's needed instead so that if the search params are updated, it includes those changes

Might be good to add a test for that too


await page.fill('[data-unscoped] input', 'hello');
await page.getByText('set message').click();
await expect(page).toHaveURL(/existing=value/);

@teemingc teemingc Jul 18, 2026

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.

Suggested change
await expect(page).toHaveURL(/existing=value/);
await test.step('preserves URL query', async () => {
await expect(page).toHaveURL((url) => url.searchParams.get('existing') === 'value');
});

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.

Remote form with JS disabled removes existing searchParams

2 participants