atoms and error boundaries
See original GitHub issueI’m trying out jotai in one of my projects and it was crashing with code like this
React.useEffect(() => {
setState(s => {
const x = {};
delete x[123][123];
});
});
and I was confused why this error wasn’t caught by the react error boundary (of react-error-boundary
fame). Then I realized that my component three was like this JotaiProvider -> ErrorBoundary -> MyComponent
so doing something like ErrorBoundary -> JotaiProvider -> ErrorBoundary -> MyComponent
helped, but it makes me realize interesting consideration that with smaller context providers I can have them closer to my component and thus making errors more local, but errors in jotai are basically globally scoped 😃
I don’t know if that’s an issue per se, but maybe a good point to consider when deciding between custom context vs global context
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (17 by maintainers)
Top Results From Across the Web
Improve Customer Experience via Error Boundaries - Medium
Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
Read more >Error Boundaries - React
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI...
Read more >loadable — Jotai, primitive and flexible state management for ...
If you don't want async atoms to suspend or throw to an error boundary (for example, for finer-grained control of loading and error...
Read more >on Twitter: "Jōtai's async atoms in action: https://t.co ...
you would have to put error boundaries around it to catch them. since jotai is using suspense, error handling comes natural, ...
Read more >React Error Boundary ft. TDD with Testing Library - YouTube
Error Boundary is a React component that catches JavaScript errors anywhere in their child component tree, which enables graceful handling ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
can confirm that v0.10.0 fixes both example on codesandbox and the issue in my app
So, with both
set*
, it showsHigh level oopsie...
, and if we comment out the first one, it showsOopsie on Crash level...
. Good point.This is because of the place we invoke atom.write function. But, I agree it’s weird. I guess this reveals another issue about batched writes.
I also find my explanation wasn’t so accurate, because it shows error boundaries. I may have misunderstood something.
Let me think if I can write a test case for this.