diff --git a/.changeset/lovely-starfishes-impress.md b/.changeset/lovely-starfishes-impress.md new file mode 100644 index 000000000000..b8e51c2ce4f5 --- /dev/null +++ b/.changeset/lovely-starfishes-impress.md @@ -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 diff --git a/documentation/docs/20-core-concepts/30-form-actions.md b/documentation/docs/20-core-concepts/30-form-actions.md index fdad1d71485a..86c3b02233a5 100644 --- a/documentation/docs/20-core-concepts/30-form-actions.md +++ b/documentation/docs/20-core-concepts/30-form-actions.md @@ -353,7 +353,7 @@ The easiest way to progressively enhance a form is to add the `use:enhance` acti
``` -> [!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 `` are both called 'action'. These docs are action-packed. Sorry. diff --git a/packages/kit/src/runtime/server/endpoint.js b/packages/kit/src/runtime/server/endpoint.js index 3d1dcd48fc26..55bcd87807b9 100644 --- a/packages/kit/src/runtime/server/endpoint.js +++ b/packages/kit/src/runtime/server/endpoint.js @@ -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'; @@ -11,10 +10,6 @@ import { method_not_allowed } from './utils.js'; * @returns {Promise} */ 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;