diff --git a/.changeset/nine-parrots-smoke.md b/.changeset/nine-parrots-smoke.md new file mode 100644 index 000000000000..db364d3136f4 --- /dev/null +++ b/.changeset/nine-parrots-smoke.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +chore: error during development when using `use:enhance` with `+server` diff --git a/packages/kit/src/runtime/server/endpoint.js b/packages/kit/src/runtime/server/endpoint.js index 55bcd87807b9..3d1dcd48fc26 100644 --- a/packages/kit/src/runtime/server/endpoint.js +++ b/packages/kit/src/runtime/server/endpoint.js @@ -1,3 +1,4 @@ +import { DEV } from 'esm-env'; import { ENDPOINT_METHODS, PAGE_METHODS } from '../../constants.js'; import { negotiate } from '../../utils/http.js'; import { Redirect } from '../control.js'; @@ -10,6 +11,10 @@ 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;