Depending on whether SSR is enabled or not, the Form Actions behave differently, and I don't mean the difference in response (rendered HTML vs. SPA shell).
After an action is invoked it can have three outcomes: success, error, or redirect.
(in this scenraio fail is analogous to success — data is also missing)
With SSR the returned the responses make sense, i.e. success re-renders the page with the new data, error renders the error page, and the redirect redirects to a new page.
The problems start when SSR is disabled. Only the redirect works as expected. In both other cases it looks like a page reload, without any indication of change.
Because I found it hard to explain in prose, I wrote down what happens in order for each case, and I point out the inconsistencies in conclusion bellow.
initial load:
data: PageData contains data returned from 3.form: ActionData is nullafter form submission:
submission successful
+page.sveltedata: PageData contains data returned from 4.form: ActionData contains data returned from 1.action calls error
+error.sveltedata: PageData is empty ({})form: ActionData is nullaction calls redirect
+page.svelte for the redirected pagedata: PageData is empty ({})form: ActionData is nullinitial load:
data: PageData contains data returned from 2.form: ActionData is nullafter form submission:
submission successful
locals are empty; cookies are available [^1]+page.sveltedata: PageData contains data returned from 3.form: ActionData is null[^1]: makes sense, because the server load is a new request, and the cookies are sent with the request - locals are not
action calls error
+error.svelte page, the error is not displayed, and the page proceeds to load as on initial loadlocals are empty; cookies are available [^1]+page.sveltedata: PageData contains data returned from 3.form: ActionData is nullaction calls redirect
+page.svelte for the locationdata: PageData is empty ({})form: ActionData is nullI think there are two problems here:
Missing error page
already described here
Missing ActionData
I think the source of this inconsistency is that without SSR the actions respond immediately, without populating the
This of course can't happen because without SSR the same static HTML is always served.
The solution is to use data, form, etc.use:enhance
I still think it would be nice if the ActionData
(and then probably also data from server load)
was available for the CSR.