Error thrown in async write result in infinite loop
See original GitHub issueTrying to debug this, it looks like the Promise
wrapped test error is constantly alternating being thrown by core/useAtom.ts#L33 and some internal React code.
This results in constant Rendering Test
messages being logged.
import { atom, Provider, useAtom } from 'jotai';
import { Suspense } from "react";
import { render } from "react-dom";
import { ErrorBoundary } from "react-error-boundary";
const testAtom = atom(undefined, (async () => {
throw new Error('test');
}));
render(<App />, document.getElementById("app"));
function App() {
return (
<Provider>
<ErrorBoundary fallbackRender={({ error }) => { return (<p>{error.toString()}</p>); }}>
<Suspense fallback={"Loading..."}>
<Test />
</Suspense>
</ErrorBoundary>
</Provider>
);
}
function Test() {
console.log('Rendering Test');
const [_, write] = useAtom(testAtom);
return (
<button onClick={() => write()}>Test</button>
);
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
How to catch error promises in infinite while-loop with async ...
You can wrap your block in a try catch : while (true) { try { await promisifiedDelay(20000); users.map(async client => { //await ......
Read more >plugin-transform-regenerator can produce infinite loop using ...
I'm using a library that uses finally blocks to handle cleanups inside async functions. Is there any way to clean this up at...
Read more >Error handling with async/await and promises, n² ... - CatchJS
Async await error handling has a bunch of edge cases. ... Will not catch errors thrown in another call stack via a setTimeout()...
Read more >JavaScript Mistake — Loops, Promises, and More
We don't want async functions as executors because when errors are thrown, they'll be lost and won't cause the newly constructed promise to ......
Read more >Python behind the scenes #12: how async/await works in Python
The core of the program is the event loop – an infinite loop that on each iteration selects ready sockets and calls the...
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
@dai-shi, perhaps this should be a separate issue for discussion, but it seems like when a write function throws an error, it should be sent back to the caller so they can catch it and use something like
useErrorHandler
fromreact-error-boundary
to display it to the user. It seems like at the moment the error is consumed and sent straight to the console.Oh, duh, I wasn’t awaiting the returned promise. Nevermind; thanks for all your help!