Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error swallowed in form action when page has SSR disabled #11757

Open
winstonewert opened this issue Jan 29, 2024 · 2 comments · May be fixed by #12063
Open

Error swallowed in form action when page has SSR disabled #11757

winstonewert opened this issue Jan 29, 2024 · 2 comments · May be fixed by #12063
Labels
bug Something isn't working forms Stuff relating to forms and form actions ready to implement please submit PRs for these issues!
Milestone

Comments

@winstonewert
Copy link

Describe the bug

I've found that when an exception is thrown in a page action and ssr = false, then I don't see the exception anywhere. I do get the 500 error response.

Reproduction

Minimal test case: https://github.com/winstonewert/sveltekit-bug-report

It's just a skeleton sveltekit project with the following +page.server.ts:

export const ssr = false;

export const actions = {
	default: async () => {
		throw new Error('Something bad!');
	}
};

And a button to trigger the post request

Logs

The absence of logs is the problem.

System Info

System:
    OS: Linux 6.5 Ubuntu 23.10 23.10 (Mantic Minotaur)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz
    Memory: 27.80 GB / 46.94 GB
    Container: Yes
    Shell: 5.2.15 - /bin/bash
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    Yarn: 1.17.3 - /usr/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
    pnpm: 8.9.2 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 120.0.6099.216
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.1.1 
    @sveltejs/kit: ^2.0.0 => 2.5.0 
    @sveltejs/vite-plugin-svelte: ^3.0.0 => 3.0.2 
    svelte: ^4.2.7 => 4.2.9 
    vite: ^5.0.3 => 5.0.12

Severity

annoyance

Additional Information

  1. The error gets returned to the call to await handle_action_request in render_page in src/runtime/server/page.js
  2. Because ssr is disabled, render_page returns await render_response
  3. The code that checks and then rethrows the error later in render_page: throw action_result.error is never executed.
@mastermakrela
Copy link

Hi, I was investigating something similar. I was confused why I can't see the data returned from the Form Actions.

And the solution was to use use:enhance on the form, because without SSR, the returned HTML is always the same, so the data handling has to happen in the browser.

@eltigerchino eltigerchino added bug Something isn't working forms Stuff relating to forms and form actions labels Mar 21, 2024
@eltigerchino
Copy link
Member

eltigerchino commented Mar 21, 2024

Yeah, it doesn't look like the default form submit is suppose to work with SSR disabled (there's no code to return the page.form variable unless SSR is enabled). Since submitting a form natively refreshes the page, and refreshing the page loads an empty shell, it can never receive the object returned by the form action. You must use use:enhance to send an action JSON request instead.

I think we at least ought to log a warning if the page has SSR disabled but it submits a native form request to an action so that this is more obvious it's not suppose to work.

@eltigerchino eltigerchino added the ready to implement please submit PRs for these issues! label Mar 21, 2024
@eltigerchino eltigerchino added this to the non-urgent milestone Mar 21, 2024
@eltigerchino eltigerchino changed the title Error swallowed in form action Error swallowed in form action when page has SSR disabled Mar 21, 2024
@mastermakrela mastermakrela linked a pull request Mar 31, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working forms Stuff relating to forms and form actions ready to implement please submit PRs for these issues!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants