solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

Error inside createRouteAction not triggering ErrorBoundary

Open dallastjames opened this issue 3 years ago • 0 comments

In the documentation, it's mentioned that if you don't explicitly handle an error on a route action then the error should bubble up to the nearest ErrorBoundary: CleanShot 2022-11-15 at 14 00 01

Given the following two components:

export function FormSection() {
  return (
    <ErrorBoundary fallback={() => <h2>Oh no! Error!</h2>}>
      <TinyForm />
    </ErrorBoundary>
  );
}
export function TinyForm() {
  const [formState, { Form }] = createRouteAction(async (data: FormData) => {
    throw new Error("Something went wrong!");
  });

  return (
    <Form>
      <label for="username">Username:</label>
      <input type="text" name="username" />
      <input type="submit" value="submit" disabled={formState.pending} />
    </Form>
  );
}

I would expect that the error being thrown in the route action bubbles up to the ErrorBoundary above, but it is not. The error is just swallowed by the routeAction. I can still manually handle errors using the recommended approach:

<Show when={formState.error}>
  <p>Oh no, there was an error: {formState.error.message}</p>
</Show>

But ideally, I'd like to ensure that these hit the Error boundaries as expected so that I can ensure I'm catching unhandled errors inside of Sentry.

A sample app with a reproduction lives here

dallastjames avatar Nov 15 '22 21:11 dallastjames