Skip to content

Commit 96642d2

Browse files
mastermakrelateemingcChew Tee Ming
authored
fix: add warning for form action responses lost without SSR (#12063)
* Add warning for form action responses lost without SSR * update changeset * Update .changeset/many-cats-breathe.md * Update packages/kit/src/runtime/server/page/index.js * Update packages/kit/src/runtime/server/page/index.js * Update packages/kit/src/runtime/server/page/index.js * cleanup --------- Co-authored-by: Tee Ming <chewteeming01@gmail.com> Co-authored-by: Chew Tee Ming <chew.tee.ming@nindatech.com>
1 parent f3b638e commit 96642d2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

.changeset/many-cats-breathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sveltejs/kit": patch
3+
---
4+
5+
fix: warn when form action responses are lost because SSR is off

packages/kit/src/runtime/server/page/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { respond_with_error } from './respond_with_error.js';
1616
import { get_option } from '../../../utils/options.js';
1717
import { get_data_json } from '../data/index.js';
1818
import { load_page_nodes } from './load_page_nodes.js';
19+
import { DEV } from 'esm-env';
1920

2021
/**
2122
* The maximum request depth permitted before assuming we're stuck in an infinite loop
@@ -99,6 +100,21 @@ export async function render_page(event, page, options, manifest, state, resolve
99100
// no server data to prerender. As a result, the load functions and rendering
100101
// only occur client-side.
101102
if (get_option(nodes, 'ssr') === false && !(state.prerendering && should_prerender_data)) {
103+
// if the user makes a request through a non-enhanced form, the returned value is lost
104+
// because there is no SSR or client-side handling of the response
105+
if (DEV && action_result && !event.request.headers.has('x-sveltekit-action')) {
106+
if (action_result.type === 'error') {
107+
console.warn(
108+
"The form action returned an error, but +error.svelte wasn't rendered because SSR is off. To get the error page with CSR, enhance your form with `use:enhance`. See https://kit.svelte.dev/docs/form-actions#progressive-enhancement-use-enhance"
109+
);
110+
} else if (action_result.data) {
111+
/// case: lost data
112+
console.warn(
113+
"The form action returned a value, but it isn't available in `$page.form`, because SSR is off. To handle the returned value in CSR, enhance your form with `use:enhance`. See https://kit.svelte.dev/docs/form-actions#progressive-enhancement-use-enhance"
114+
);
115+
}
116+
}
117+
102118
return await render_response({
103119
branch: [],
104120
fetched,

0 commit comments

Comments
 (0)