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(remix-react): An error in MetaFunction or LinkFunction should render ErrorBoundary #3674

Closed
wants to merge 12 commits into from

Conversation

mcansh
Copy link
Collaborator

@mcansh mcansh commented Jul 7, 2022

Signed-off-by: Logan McAnsh logan@mcan.sh

Closes #3140

  • Docs
  • Tests

Testing Strategy:

  • these tests cover the changed code: error-boundary-test.ts
  • I also opened up a new playground to make sure it all worked there as well.

@mcansh mcansh changed the title chore: update build step to copy prior to generating types fix(remix-react): An error in MetaFunction or LinkFunction should render ErrorBoundary Jul 7, 2022
@mcansh mcansh linked an issue Jul 7, 2022 that may be closed by this pull request
Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

I think I must be missing something here, but I don't see any behavioral changes here. I'm pretty sure the code does exactly the same thing before and after.

package.json Outdated Show resolved Hide resolved
packages/remix-react/components.tsx Outdated Show resolved Hide resolved
packages/remix-react/links.ts Outdated Show resolved Hide resolved
@mcansh
Copy link
Collaborator Author

mcansh commented Jul 8, 2022

little more digging, looks like if you have a custom ErrorBoundary we render the generic Unexpected Server Error
image

but if you don't have one, it renders the default RemixErrorBoundary
image

@mcansh mcansh marked this pull request as draft July 8, 2022 17:31
@mcansh mcansh force-pushed the logan/rem-1298-meta-link-error-boundary branch from 1bd7cc0 to 8da006b Compare July 8, 2022 22:22
@changeset-bot
Copy link

changeset-bot bot commented Jul 8, 2022

⚠️ No Changeset found

Latest commit: 6e57656

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

@@ -470,6 +477,32 @@ async function handleDocumentRequest({
} catch (error: any) {
responseStatusCode = 500;

// next up, we'll verify that `meta` returned without error
try {
await callRouteMeta({
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if there's any use in distinguishing errors thrown when calling a route meta() function here from errors thrown when rendering the <meta> tags. The rendering is far more in our control and we should be able to be pretty confident it won't throw render errors. The exported meta function contents are out of our control - but we do control the execution of it in our own <Meta> component.

Spitballing here but what if we did something like this in <Meta>

for (let match of matches) {
  let routeId = match.route.id;
  try {
    let routeMeta = routeModule.meta({ data, parentsData, params, location })
    ...
  } catch (error) {
    // Re-throw the error and associate it with the routeId that threw it
    throw new MetaError(routeId, error);
  }
}

Then we could identify the error in this handleDocumentRequest catch block as a meta-specific error (via instanceof MetaError) and know the routeId that caused it and look for the nearest ancestor boundary (i.,e., prevent re-calling the problematic meta on the second pass - but attempt to call the successful ones above it).

This is effectively what we're doing with the mutable boundaryIds (identifying how deep we got) - but we have no choice there since it's React calling them, not us. meta isn't subject to that same restriction so we could be a bit more direct in the identification of the problematic routeId.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually we'd still need some logic changes in Meta to do that too I think. It doesn't have the concept of renderableMatches that we have for getDocumentHeaders which I think is what it would need to not call child's meta function on the second pass if we had identified parent as the renderable boundary.

@mcansh mcansh force-pushed the logan/rem-1298-meta-link-error-boundary branch from f2c785c to d59d138 Compare July 20, 2022 19:34
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
@mcansh mcansh force-pushed the logan/rem-1298-meta-link-error-boundary branch from d59d138 to aae7c22 Compare February 3, 2023 17:05
Signed-off-by: Logan McAnsh <logan@mcan.sh>
@mcansh mcansh force-pushed the logan/rem-1298-meta-link-error-boundary branch from 895def7 to 7fc50e0 Compare February 3, 2023 17:27
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
Signed-off-by: Logan McAnsh <logan@mcan.sh>
@mcansh mcansh force-pushed the logan/rem-1298-meta-link-error-boundary branch from 56fda0d to d819080 Compare February 3, 2023 20:01
Signed-off-by: Logan McAnsh <logan@mcan.sh>
@mcansh mcansh force-pushed the logan/rem-1298-meta-link-error-boundary branch from b373654 to 6e57656 Compare February 3, 2023 20:52
@MichaelDeBoey MichaelDeBoey removed the request for review from kentcdodds May 1, 2023 23:15
@brophdawg11
Copy link
Contributor

Closing for now, can re-open if/when we come back to this.

@brophdawg11 brophdawg11 closed this Aug 2, 2023
@MichaelDeBoey MichaelDeBoey deleted the logan/rem-1298-meta-link-error-boundary branch August 3, 2023 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

An error in MetaFunction or LinkFunction is not caught by ErrorBoundary
4 participants