From c340350307233f9254dd638650b7641892f8cc83 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 19 Dec 2024 15:18:56 +0800 Subject: [PATCH 1/4] add dev only error --- packages/kit/src/runtime/server/endpoint.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/kit/src/runtime/server/endpoint.js b/packages/kit/src/runtime/server/endpoint.js index 55bcd87807b9..68a01345efce 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,12 @@ 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( + 'Methods from $app/forms such as use:enhance and deserialize should only be used with SvelteKit form actions' + ); + } + const method = /** @type {import('types').HttpMethod} */ (event.request.method); let handler = mod[method] || mod.fallback; From 262c32ce308e87df9dc590b7cbb8e606a901a19b Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 19 Dec 2024 15:27:56 +0800 Subject: [PATCH 2/4] message --- packages/kit/src/runtime/server/endpoint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit/src/runtime/server/endpoint.js b/packages/kit/src/runtime/server/endpoint.js index 68a01345efce..c78600ca7d09 100644 --- a/packages/kit/src/runtime/server/endpoint.js +++ b/packages/kit/src/runtime/server/endpoint.js @@ -13,7 +13,7 @@ import { method_not_allowed } from './utils.js'; export async function render_endpoint(event, mod, state) { if (DEV && event.request.headers.get('x-sveltekit-action') === 'true') { throw new Error( - 'Methods from $app/forms such as use:enhance and deserialize should only be used with SvelteKit form actions' + 'use:enhance should only be used with SvelteKit form actions' ); } From a128d5262b0787d3a152b46bbeb0b73d75c2fa50 Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 19 Dec 2024 15:31:17 +0800 Subject: [PATCH 3/4] changeset --- .changeset/nine-parrots-smoke.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nine-parrots-smoke.md 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` From 9400deb82b8ff2782832e4957db6601ce0e85a5f Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 19 Dec 2024 16:13:56 +0800 Subject: [PATCH 4/4] format --- packages/kit/src/runtime/server/endpoint.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/kit/src/runtime/server/endpoint.js b/packages/kit/src/runtime/server/endpoint.js index c78600ca7d09..3d1dcd48fc26 100644 --- a/packages/kit/src/runtime/server/endpoint.js +++ b/packages/kit/src/runtime/server/endpoint.js @@ -12,9 +12,7 @@ import { method_not_allowed } from './utils.js'; */ 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' - ); + throw new Error('use:enhance should only be used with SvelteKit form actions'); } const method = /** @type {import('types').HttpMethod} */ (event.request.method);