jotai: atoms and error boundaries
I’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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (17 by maintainers)
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.
I tried to reproduce it again, and as far as it looks both 0.7 and 0.9 work without issues. So I’m closing this because that thing with hot reload is not a huge deal, and I don’t see those issues that I first saw.
yes, this one works as expected. Did you just move atom into different file and that’s it? 😃
Anyway 😃 I will try to reproduce the exact issue I was having on my end if we can’t do anything with this hot reload example 😃