-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: explain why json() cannot be used in form actions
#12829
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
Changes from 3 commits
91ebc2d
bf60632
d279ff5
f62eaeb
8116883
4be8f45
b8e8cc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sveltejs/kit': patch | ||
| --- | ||
|
|
||
| fix: explain why `json()` cannot be used in form actions | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,13 @@ function try_deserialize(data, fn, route_id) { | |
| // If we're here, the data could not be serialized with devalue | ||
| const error = /** @type {any} */ (e); | ||
|
|
||
| // if someone tries to use `json()` in their action | ||
| if (data instanceof Response) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's nothing really specific in this error message about a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It still catches it but the error message is usually "Cannot stringify arbitrary non-POJOs" which can be unhelpful. We could combine the two but I'm wondering if there are instances where devalue's error message is preferred. |
||
| throw new Error( | ||
| `Data returned from action inside ${route_id} is not serializable. Form actions need to return plain objects or fail(). e.g. return { success: true } or return fail(400, { message: "invalid" });` | ||
teemingc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
|
|
||
| if ('path' in error) { | ||
teemingc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let message = `Data returned from action inside ${route_id} is not serializable: ${error.message}`; | ||
| if (error.path !== '') message += ` (data.${error.path})`; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.