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

RFC: standardize error handling in React components #2937

Closed
twschiller opened this issue Mar 12, 2022 · 6 comments
Closed

RFC: standardize error handling in React components #2937

twschiller opened this issue Mar 12, 2022 · 6 comments
Labels
developer experience Stale user experience Improve the user experience (UX)

Comments

@twschiller
Copy link
Contributor

twschiller commented Mar 12, 2022

Context:

  • We have an ErrorBoundary component
  • Many components also contain logic for displaying error state

Approaches:

  1. Components throw and ancestor is responsible for including an ErrorBoundary at the appropriate level. (This is my preference, since we'd want it anyway for unexpected errors, e.g., from bugs in our code)
  2. Components know how to render their own error state. And introduce a standard error presentational component

Situations to consider:

  1. A component uses a RTK Query that errors

Example code. Should this use useEffect or just throw directly from the render loop?

const {error} = useMyQuery();

if (error) {
  throw error;
}

Related:

@twschiller twschiller added developer experience user experience Improve the user experience (UX) labels Mar 12, 2022
@twschiller twschiller changed the title Standardize handling errors in React components Standardize error handling in React components Mar 12, 2022
@twschiller twschiller changed the title Standardize error handling in React components RFC: standardize error handling in React components Mar 12, 2022
@BLoe
Copy link
Collaborator

BLoe commented Jun 27, 2023

@grahamlangford I'm not sure if there are really useful action items out of this one anymore.

My understanding of the current paradigm is:

  • We use explicit ErrorBoundary components at various levels based on how we want to segment the UI, and which pieces can be independently reloaded/refreshed (this probably isn't super clean and could be improved in some places)
  • Components are responsible for throwing or showing their own errors based on product specs / designs / etc.
  • It's up to each component/call-site to determine if an RTK Query error should be suppressed, shown in the UI, or thrown up to parents

@BLoe
Copy link
Collaborator

BLoe commented Jun 27, 2023

@twschiller
Copy link
Contributor Author

We also have AsyncStateGate now as well that can help with the error state for async data

@BLoe
Copy link
Collaborator

BLoe commented Jun 27, 2023

Copy link

This issue will be closed in 7 days unless the stale label is removed, or a comment is added to the issue.

@github-actions github-actions bot added the Stale label Mar 28, 2024
Copy link

github-actions bot commented Apr 4, 2024

This issue was closed because it has been stale for 7 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer experience Stale user experience Improve the user experience (UX)
Projects
None yet
Development

No branches or pull requests

2 participants