sveltejs / sveltejs/kit

Way to differentiate a progressively enhanced form submit.

Open
#10,991 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Consider the following scenario.

  1. User submits a login form.
  2. Server validates the request.
  3. Server responds with a 302 redirect response, with a Set-Cookie header.

If SameSite=strict is set in the Set-Cookie header, it would

  • work in a progressively enhanced form submit
  • might not work in a non-enhanced, no-JS form submit

This is because step 3 does not work in some recent versions of Firefox and Chrome.

We could see the Cookie from the browser storage inspect tab, but not in the request immediately following the 302 response.

Progressively enhanced form works, because the Fetch request responds with 200 OK.

Describe the proposed solution

An alternative to RequestEvent.isDataRequest such as isEnhancedFormRequest.

isDataRequest: boolean;

true if the request comes from the client asking for +page/layout.server.js data.

Alternatives considered

Considered workarounds using the following request headers:

  • x-sveltekit-action : not included in non-enhanced submit.
  • content-type : is multipart/form-data; in enhanced submit.
Importance

would make my life easier

Additional Information

In a non-enhanced form submit, the following HTML header can be returned for client-side redirect without JavaScript. Throwing redirect with an option for client-side redirect can help with this issue (if the server is returning a SSR HTML).

<head><meta http-equiv="refresh" content="0; url='REDIRECT_URL'"></head>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the RequestEvent.isDataRequest entry in the public types documentation and the issue's examples of x-sveltekit-action and content-type. Trace how enhanced and non-enhanced form requests are currently distinguished. Done means providing a reliable way for server code to identify enhanced form submissions without relying on headers that differ incidentally.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.