Skip to content

chore: revert dev error when using use:enhance with +server #13397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading