router: Suspense error: A component suspended while responding to synchronous input
Describe the bug
react-router causes the following React error:
A component suspended while responding to synchronous input.
This will cause the UI to be replaced with a loading indicator. To fix, updates that suspend should be wrapped with startTransition.
Full stack trace as shown in console
throwException@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/react-dom_client.js?v=ed25c456:13798:43 handleError@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/react-dom_client.js?v=ed25c456:18529:29 renderRootSync@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/react-dom_client.js?v=ed25c456:18614:26 recoverFromConcurrentError@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/react-dom_client.js?v=ed25c456:18233:42 performSyncWorkOnRoot@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/react-dom_client.js?v=ed25c456:18375:28 flushSyncCallbacks@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/react-dom_client.js?v=ed25c456:8776:30 node_modules/react-dom/cjs/react-dom.development.js/ensureRootIsScheduled/<@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/react-dom_client.js?v=ed25c456:18124:21CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 Outlet2@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:938:25 div PostsRouteComponent@https://xr7dd3-3001.csb.app/src/main.tsx?t=1702934734809:136:38 MatchInner@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:903:20 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 Outlet2@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:938:25 RootComponent MatchInner@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:903:20 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 Matches@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:842:18 RouterProvider@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:1048:24 QueryClientProvider@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-XI5YTT3J.js?v=ed25c456:2592:27 Warning: Error in route match: /posts/post CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 Outlet2@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:938:25 div PostsRouteComponent@https://xr7dd3-3001.csb.app/src/main.tsx?t=1702934734809:136:38 MatchInner@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:903:20 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 Outlet2@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:938:25 RootComponent MatchInner@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:903:20 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 Matches@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:842:18 RouterProvider@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:1048:24 QueryClientProvider@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-XI5YTT3J.js?v=ed25c456:2592:27 Warning: Error in route match: /posts/post CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 Outlet2@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:938:25 div PostsRouteComponent@https://xr7dd3-3001.csb.app/src/main.tsx?t=1702934734809:136:38 MatchInner@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:903:20 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 Outlet2@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:938:25 RootComponent MatchInner@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:903:20 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 SafeFragment@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:865:52 Match@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:867:15 CatchBoundaryImpl@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:649:5 CatchBoundary@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:631:27 Matches@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:842:18 RouterProvider@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-GVDQM46P.js?v=ed25c456:1048:24 QueryClientProvider@https://xr7dd3-3001.csb.app/node_modules/.vite/deps/chunk-XI5YTT3J.js?v=ed25c456:2592:27
Your Example Website or App
https://codesandbox.io/p/devbox/cool-poincare-xr7dd3?file=%2Fsrc%2Fmain.tsx%3A20%2C32
Steps to Reproduce the Bug or Issue
- go to https://codesandbox.io/p/devbox/cool-poincare-xr7dd3?file=%2Fsrc%2Fmain.tsx%3A20%2C32
- click on posts
- click on the first post
- click on the second post
- error is shown
Expected behavior
no error messages
Screenshots or Videos
https://github.com/TanStack/router/assets/6340397/d994f0c1-fabf-44c3-b261-a8eb2b5fb012
Platform
- OS: macOS
- Browser: Firefox
- Version: 120
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 15 (5 by maintainers)
it would be good to update the documentation as this is not mentioned
Just ran into this issue.
I solved it by wrapping the RouterProvider with Suspense.
I solved it by wrapping the devtools in a
Suspensecomponent:@StringKe, I solved it like this:
I just ran into this issue RouterProvider needs to be wrapped with Suspense. But why is this error occurring now? I tested this yesterday and it didn’t have this issue. Weird.
The solution here is to add a suspense fallback somewhere for
useInfinityQueryto fall back on. TSR doesn’t add any suspense wrappers by default unless you use aloaderorpendingComponentexplicitly.Add this to the
/posts/$postIdroute options and you’ll be good to go: