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

Make submission result/error consistent for initFromFlash #1552

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

frenzzy
Copy link
Contributor

@frenzzy frenzzy commented Jun 17, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • infrastructure changes
  • Other... Please describe:

What is the current behavior?

Currently, when an error is thrown from the server function, the client-side submission logic and server-side init from flash logic behave differently:

const MyComponent = () => {
  const sumission = useSubmision(myAction)

  // SSR
  console.log(getRequestEvent()?.router?.submission.result) // Error
  console.log(getRequestEvent()?.router?.submission.error) // undefined

  createEffect(() => {
    if (sumission.pending === false) {
      // CSR
      console.log(sumission.result) // null
      console.log(sumission.error) // Error
    }
  })

  // ...
}

Error appears in submission.error when not relying on flash.

What is the new behavior?

Consistent behavior of submission.error for the init from flash case. Error is in submission.error when an error is thrown from the server function.

Other information

Link to the thread in Discord with additional details

Copy link

changeset-bot bot commented Jun 17, 2024

⚠️ No Changeset found

Latest commit: 2363a02

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@ryansolid
Copy link
Member

Oh right.. I missed moving this all the way across when i added .error

@ryansolid ryansolid merged commit d82af5b into solidjs:main Jun 17, 2024
1 check passed
@frenzzy frenzzy deleted the patch-2 branch June 18, 2024 04:07
@ryansolid
Copy link
Member

Ok I have a new fix for this issue. I do want to remind you though that throwing errors in actions is not a recommended approach in general because you lose typescript support. But now at least it works properly.

ryansolid added a commit that referenced this pull request Jun 18, 2024
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.

2 participants