Skip to content

Commit

Permalink
chore: revert dev error when using use:enhance with +server (#13397)
Browse files Browse the repository at this point in the history
This PR reverts #13197 since it cause an error for users that used SuperForm's helper that made +server responses compatible with use:enhance.
  • Loading branch information
eltigerchino authored Jan 31, 2025
1 parent 180fa34 commit 09296d0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-starfishes-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

chore: don't error during development when using `use:enhance` with `+server` as some third party libraries make it possible to POST forms to it
2 changes: 1 addition & 1 deletion documentation/docs/20-core-concepts/30-form-actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ The easiest way to progressively enhance a form is to add the `use:enhance` acti
<form method="POST" +++use:enhance+++>
```
> [!NOTE] `use:enhance` can only be used with forms that have `method="POST"`. It will not work with `method="GET"`, which is the default for forms without a specified method. Attempting to use `use:enhance` on forms without `method="POST"` will result in an error.
> [!NOTE] `use:enhance` can only be used with forms that have `method="POST"` and point to actions defined in a `+page.server.js` file. It will not work with `method="GET"`, which is the default for forms without a specified method. Attempting to use `use:enhance` on forms without `method="POST"` or posting to a `+server.js` endpoint will result in an error.
> [!NOTE] Yes, it's a little confusing that the `enhance` action and `<form action>` are both called 'action'. These docs are action-packed. Sorry.
Expand Down
5 changes: 0 additions & 5 deletions packages/kit/src/runtime/server/endpoint.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DEV } from 'esm-env';
import { ENDPOINT_METHODS, PAGE_METHODS } from '../../constants.js';
import { negotiate } from '../../utils/http.js';
import { Redirect } from '../control.js';
Expand All @@ -11,10 +10,6 @@ import { method_not_allowed } from './utils.js';
* @returns {Promise<Response>}
*/
export async function render_endpoint(event, mod, state) {
if (DEV && event.request.headers.get('x-sveltekit-action') === 'true') {
throw new Error('use:enhance should only be used with SvelteKit form actions');
}

const method = /** @type {import('types').HttpMethod} */ (event.request.method);

let handler = mod[method] || mod.fallback;
Expand Down

0 comments on commit 09296d0

Please sign in to comment.