Skip to content

fix(site): ensure Error Boundary catches render errors correctly #15963

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

Merged
merged 11 commits into from
Jan 3, 2025

Conversation

Parkreiner
Copy link
Member

@Parkreiner Parkreiner commented Dec 26, 2024

No issue or design to link to. Squeezing this in between other stuff

Changes made

  • Replaced previous ErrorBoundary functionality with GlobalErrorBoundary component
  • Wired up GlobalErrorBoundary to React Router rather than the top of the app

Screenshots

Before
Screenshot 2024-12-26 at 5 49 54 PM

After
Screenshot 2024-12-26 at 5 50 25 PM

Screenshot 2024-12-26 at 5 50 36 PM

Notes

  • The visual design of the error boundary (and maybe some of the functionality) should definitely change to be in line with our design kit, but I think that can wait. I did try to mirror our old and new design tokens as closely as possible (erring on the side of the old if there were conflicts), but to honest, I think the most important thing is that our error-handling functionality is now working correctly for the first time in ~2 years

@Parkreiner Parkreiner self-assigned this Dec 26, 2024
Comment on lines 57 to 59
type={
props.type === undefined && Comp === "button" ? "button" : props.type
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Small change to make sure that you have to opt into submit behavior for true buttons

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m not sure I fully understand the value or use case for this 🤔. Could you share an example to help clarify? At first glance, it seems like the type prop should be the consumer’s responsibility rather than something built into the component.

Copy link
Member Author

@Parkreiner Parkreiner Dec 27, 2024

Choose a reason for hiding this comment

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

So, I feel that +90% of the time, when you have a <button>, you want it to be type="button" instead of the default type="submit", and even experienced frontend engineers can forget to do that. That sometimes leads to forms accidentally getting submitted when you didn't mean for them to. I think it's a more reasonable default value that can't ever be made official because of HTML backwards-compatibility

And since the Radix button component is polymorphic, we don't have any linting rules to catch that you didn't set the type, but also because it's polymorphic, the final output might not be an actual button. If we use asChild to style a link like a button, we can't always assume that we can attach a type attribute. <a> doesn't support the attribute, so while React would let us add it no problem, the HTML would be invalid

So basically, the check makes it so that buttons will default to type="button" if the output would be a button, and if the prop wasn't already set. Otherwise, yeah, it does fall to the user to wire things up correctly

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think it would make sense to summarize this decision and add it as a comment? I’m concerned we might forget this decision in the future and accidentally remove it, as it’s not a very common or usual approach.

ref={ref}
{...props}
className={cn(buttonVariants({ variant, size }), className)}
Copy link
Member Author

Choose a reason for hiding this comment

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

We had a typo where we were accidentally passing the consumer class name into CVA, instead of passing it directly to cn

@Parkreiner Parkreiner changed the title fix: Ensure that React Error Boundary catches render errors correctly fix: ensure that React Error Boundary catches render errors correctly Dec 26, 2024
@Parkreiner Parkreiner changed the title fix: ensure that React Error Boundary catches render errors correctly fix(site): ensure Error Boundary catches render errors correctly Dec 26, 2024
</svg>

<div className="text-content-primary flex flex-col gap-1">
<h1 className="text-2xl font-normal m-0">{errorPageTitle}</h1>
Copy link
Member Author

Choose a reason for hiding this comment

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

@BrunoQuaresma I was wondering about this: I swear Tailwind's preflight styles get rid of all margins, period. So I wasn't sure why I as still getting them for headers and paragraphs

I saw a few other components using this, but I wasn't sure if we had to override Tailwind to get it to work with our current MUI setup

Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently, we’ve disabled Tailwind’s preflight option to simplify integration with MUI. Hopefully, we can enable it again soon.

References:

<rect width="68" height="49" />
</clipPath>
</defs>
</svg>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Since you’re already working on this part of the code, maybe we could replace this long SVG with the Coder logo component we use for the navbar. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not a nit at all. This component was originally code for the registry that I repurposed, and I forgot to see if we had an existing logo we could swap in

I'll get that fixed

@BrunoQuaresma
Copy link
Collaborator

Awesome work, and thanks so much for getting this fixed 🙏. The only blocker for me is the decision in the Button component regarding passing a default value for type.

@Parkreiner Parkreiner merged commit f6d37f6 into main Jan 3, 2025
29 checks passed
@Parkreiner Parkreiner deleted the mes/error-boundary-fix branch January 3, 2025 17:26
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants