solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
4.93k stars 371 forks source link

Make submission result/error consistent for initFromFlash #1552

Closed frenzzy closed 1 week ago

frenzzy commented 1 week ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

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

changeset-bot[bot] commented 1 week ago

⚠️ No Changeset found

Latest commit: 2363a0250991037e5ae4cc153291fb874ff9ffe3

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 commented 1 week ago

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

ryansolid commented 1 week ago

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.