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

fix: explain why json() cannot be used in form actions #12829

Merged
merged 7 commits into from
Oct 23, 2024

Conversation

eltigerchino
Copy link
Member

@eltigerchino eltigerchino commented Oct 18, 2024

closes #12787

Adds a check to see if the data being returned is a Response object (such as with the helper method json()), then replies with a more helpful error message.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

Copy link

changeset-bot bot commented Oct 18, 2024

🦋 Changeset detected

Latest commit: b8e8cc7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -280,6 +280,14 @@ 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's nothing really specific in this error message about a Response, so I'm wondering why the if below doesn't catch it. It seems like we could combine the two. Maybe they need to check if it's an instance of DevalueError or if name is DevalueError?

Copy link
Member Author

@eltigerchino eltigerchino Oct 19, 2024

Choose a reason for hiding this comment

The 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.

@dummdidumm dummdidumm merged commit 723eb8b into main Oct 23, 2024
13 checks passed
@dummdidumm dummdidumm deleted the better-devalue-error-message branch October 23, 2024 21:23
@github-actions github-actions bot mentioned this pull request Oct 23, 2024
benmccann added a commit that referenced this pull request Oct 25, 2024
closes #12787

Adds a check to see if the data being returned is a Response object (such as with the helper method json()), then replies with a more helpful error message.
---------

Co-authored-by: Ben McCann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check on Response being returned from form actions?
3 participants