Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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/many-cats-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: warn when form action responses are lost because SSR is off
23 changes: 23 additions & 0 deletions packages/kit/src/runtime/server/page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { respond_with_error } from './respond_with_error.js';
import { get_option } from '../../../utils/options.js';
import { get_data_json } from '../data/index.js';
import { load_page_nodes } from './load_page_nodes.js';
import { DEV } from 'esm-env';

/**
* The maximum request depth permitted before assuming we're stuck in an infinite loop
Expand Down Expand Up @@ -99,6 +100,28 @@ export async function render_page(event, page, options, manifest, state, resolve
// no server data to prerender. As a result, the load functions and rendering
// only occur client-side.
if (get_option(nodes, 'ssr') === false && !(state.prerendering && should_prerender_data)) {
// if SSR is turned off, and the user makes a request through a non-enhanced form,
// the returned value is lost because neither the server nor the client will handle it
if (DEV) {
const no_enhance = !event.request.headers.has('x-sveltekit-action');

if (action_result && no_enhance) {
if (action_result.type === 'error') {
console.warn(
"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"
);
}
// for type: 'success' and type: 'failure'
else if (action_result.data) {
/// case: lost data
console.warn(
"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"
);
}
// type 'redirect' is returned immediately, so we don't need to handle it here
}
}

return await render_response({
branch: [],
fetched,
Expand Down