Skip to content

fix: handle target attribute on remote form redirects#15457

Merged
teemingc merged 10 commits intosveltejs:mainfrom
ai-man-codes:fix/remote-form-target-blank
Mar 6, 2026
Merged

fix: handle target attribute on remote form redirects#15457
teemingc merged 10 commits intosveltejs:mainfrom
ai-man-codes:fix/remote-form-target-blank

Conversation

@ai-man-codes
Copy link
Contributor

@ai-man-codes ai-man-codes commented Feb 28, 2026

closes #15197


  • 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

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

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

Problem

Remote forms with target="_blank" did not open the redirect destination in a new tab. Instead, the current tab would navigate to the redirect URL, making target="_blank" completely ignored for both internal and external redirects.

Solution

Check the form element's target attribute before deciding how to navigate. If it's _blank or _new, use window.open() instead of _goto()

I have ran all the tests and there were no issues.

@changeset-bot
Copy link

changeset-bot bot commented Feb 28, 2026

🦋 Changeset detected

Latest commit: e530b52

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

@svelte-docs-bot
Copy link

@ai-man-codes
Copy link
Contributor Author

@teemingc can you please review this PR ? Thank you

@teemingc teemingc added the forms Stuff relating to forms and form actions label Mar 5, 2026
Copy link
Member

@teemingc teemingc left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! There are some additional edge cases we need to account for which I've highlighted in the comments. Also, there might be a way to simplify the window opening handling.

@ai-man-codes
Copy link
Contributor Author

Hey @teemingc, thanks for the detailed review. I have updated the code and yes there was a better way of handling this, I tried to implement that and also added an additional test.

Copy link
Member

@teemingc teemingc left a comment

Choose a reason for hiding this comment

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

Thank you!

@teemingc teemingc merged commit 56fa4fa into sveltejs:main Mar 6, 2026
25 checks passed
@github-actions github-actions bot mentioned this pull request Mar 5, 2026
Copilot AI pushed a commit to Stadly/kit that referenced this pull request Mar 6, 2026
closes sveltejs#15197

---

- [ ] 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
- [x] This message body should clearly illustrate what problems it
solves.
- [x] Ideally, include a test that fails without this PR but passes with
it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more
packages' changelogs, generate a changeset by running `pnpm changeset`
and following the prompts. Changesets that add features should be
`minor` and those that fix bugs should be `patch`. Please prefix
changeset messages with `feat:`, `fix:`, or `chore:`.

### Edits

- [x] Please ensure that 'Allow edits from maintainers' is checked. PRs
without this option may be closed.

---

### Problem

Remote forms with ```target="_blank"``` did not open the redirect
destination in a new tab. Instead, the current tab would navigate to the
redirect URL, making ```target="_blank"``` completely ignored for both
internal and external redirects.

### Solution

Check the form element's target attribute before deciding how to
navigate. If it's``` _blank``` or ```_new```, use ```window.open()```
instead of ```_goto()```

I have ran all the tests and there were no issues.

---------

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
elliott-with-the-longest-name-on-github pushed a commit that referenced this pull request Mar 11, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @sveltejs/kit@2.54.0

### Minor Changes

- feat: allow error boundaries to catch errors on the server
([#15308](#15308))

### Patch Changes

- chore: upgrade `devalue`
([#15535](#15535))


- fix: don't wait for remote functions that are not awaited in the
template ([#15280](#15280))


- feat: allow `resolve()` to accept pathnames with a search string
and/or hash ([#15458](#15458))


- chore: remove deprecation warnings for `config.kit.files.*` options
when validating the Svelte config file
([#15482](#15482))


- fix: handles form target attribute in remote form redirects
([#15457](#15457))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
dlrobson added a commit to dlrobson/dlrobson.github.io that referenced this pull request Mar 22, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [@sveltejs/kit](https://svelte.dev) ([source](https://github.com/sveltejs/kit/tree/HEAD/packages/kit)) | [`2.53.4` → `2.55.0`](https://renovatebot.com/diffs/npm/@sveltejs%2fkit/2.53.4/2.55.0) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@sveltejs%2fkit/2.55.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@sveltejs%2fkit/2.53.4/2.55.0?slim=true) |

---

### Release Notes

<details>
<summary>sveltejs/kit (@&#8203;sveltejs/kit)</summary>

### [`v2.55.0`](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2550)

[Compare Source](https://github.com/sveltejs/kit/compare/@sveltejs/kit@2.54.0...@sveltejs/kit@2.55.0)

##### Minor Changes

- feat: page and layout params with matchers are now type narrowed in `$app/types`, leading to better type safety when working with params in `$app/types`, `$app/state`, and hooks. ([#&#8203;15502](sveltejs/kit#15502))

### [`v2.54.0`](https://github.com/sveltejs/kit/blob/HEAD/packages/kit/CHANGELOG.md#2540)

[Compare Source](https://github.com/sveltejs/kit/compare/@sveltejs/kit@2.53.4...@sveltejs/kit@2.54.0)

##### Minor Changes

- feat: allow error boundaries to catch errors on the server ([#&#8203;15308](sveltejs/kit#15308))

##### Patch Changes

- chore: upgrade `devalue` ([#&#8203;15535](sveltejs/kit#15535))

- fix: don't wait for remote functions that are not awaited in the template ([#&#8203;15280](sveltejs/kit#15280))

- feat: allow `resolve()` to accept pathnames with a search string and/or hash ([#&#8203;15458](sveltejs/kit#15458))

- chore: remove deprecation warnings for `config.kit.files.*` options when validating the Svelte config file ([#&#8203;15482](sveltejs/kit#15482))

- fix: handles form target attribute in remote form redirects ([#&#8203;15457](sveltejs/kit#15457))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44NC4yIiwidXBkYXRlZEluVmVyIjoiNDMuODQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: https://forgejo.tail5a98.ts.net/gooilers123/monolith/pulls/45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forms Stuff relating to forms and form actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remote form does not respect target="_blank"

2 participants