Skip to content

Commit

Permalink
fix: add warning for form action responses lost without SSR (#12063)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent f3b638e commit 96642d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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
16 changes: 16 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,21 @@ 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 the user makes a request through a non-enhanced form, the returned value is lost
// because there is no SSR or client-side handling of the response
if (DEV && action_result && !event.request.headers.has('x-sveltekit-action')) {
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"
);
} 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"
);
}
}

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

0 comments on commit 96642d2

Please sign in to comment.