question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

atoms and error boundaries

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
JLarkycommented, Oct 19, 2020

can confirm that v0.10.0 fixes both example on codesandbox and the issue in my app

1reaction
dai-shicommented, Oct 17, 2020

So, with both set*, it shows High level oopsie..., and if we comment out the first one, it shows Oopsie 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.

We throw errors in render (atom.read) to error boundaries, but for atom.write we throw errors to the write function (even if it’s async write).

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found