Suspense around Outlets
I am using Apollo Client with Tanstack Router. I have wrapped an
<Outlet />
in a <Suspense>
and I am using useReadQuery
to receive preloaded data from the loader
I would assume this would trigger the Suspense fallback based on this line from the Apollo documenation
The preload function returns a queryRef that is passed to useReadQuery to read the query data and suspend the component while loading.
Here is my example code
route.tsx
$dealId.tsx
This layout does not show my Suspense fallback in the route.tsx
file. However when I pass down the dealQueryRef
to the <DealInfo />
component, wrap it in a <Suspense>
and call useReadQuery
from inside the fallback shows up correctly in the $dealId.tsx
route.
Perhaps @jerelmiller might be of assistance as well.Apollo GraphQL Docs
Suspense
5 Replies
fascinating-indigoOP•4mo ago
Based on the example from This does show something as explained in the docs. When I put
Deferred Data Loading
I thought just wrapping the <Outlet />
in the route.tsx
would suffice when the useReadQuery
suspended the Route component
pendingComponent
isn't showing anything as wellpendingComponent
in my $dealId.tsx
route it works as expected.
Is pendingComponent
supposed to act as the <Suspense>
around an <Outlet />
and we are not supposed to wrap <Outlet />
s?ugly-tan•4mo ago
yes if you use useSuspenseQuery, the pending component will be rendered if data is loading. But keep in mind, that it will only show, when data takes longer as the default minimum time defined in your router.
those are the defaults. So if you query takes longer than 500ms the pending component will be shown for 1000ms.
continuing-cyan•3mo ago
I'm facing the same issue with Tanstack Query.
- Wrapping
<Outlet />
with <Suspense />
never renders the fallback component.
- Wrapping the child component directly inside of <Suspense /> works fine.
I might be missing something but it feels like it should work either way, regardless of defaultPendingMs
, defaultPendingMinMs
or defaultPreloadDelay
.ugly-tan•3mo ago
did you try this setup? I think that is how you should be implementing it. Outlets are already wrapped with Suspense.
continuing-cyan•3mo ago
After further testing with a fake fetch with 3 seconds delay and lightweight rendering on the arrival page I can confirm that everything works as expected. My api call resolving fast enough and my arrival page heavy rendering in dev mode alongside
defaultPendingMs
might have been the culprits. I won't do further testing as I no longer need a fix.