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

fix: createAsync - catch errors of prev to avoid bubbling error up

Open madaxen86 opened this issue 8 months ago • 1 comments

currently when the inner function of createAsync's inner function throws after an arg has updated, the error will not be caught by the closest ErrorBoundary that wraps the accessor. It will bubble up instead. Which is kind of inconsistent, because if there is an initial error it will be caught by the closest ErrorBoundary

wrapping the the prev in catchError and returning undefined instead resolves this.

[resource] = createResource(
    () =>
      subFetch(
        fn,
        catchError(
          () => untrack(prev),
          () => undefined
        )
      ),
    v => v,

Also added tests for a few different simple scenarios of create async.

Simple reproduction

madaxen86 avatar Jun 10 '25 22:06 madaxen86

🦋 Changeset detected

Latest commit: 8885abf974a65b0914362d739b56770d555c45ae

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

This PR includes changesets to release 1 package
Name Type
@solidjs/router 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

changeset-bot[bot] avatar Jun 11 '25 17:06 changeset-bot[bot]

Thank you. There are definitely some gaps because the way we hacked around createResource.

ryansolid avatar Nov 10 '25 18:11 ryansolid