-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deferring expense logs loader data not working when navigating expense detail pages. #129
Comments
SolutionWe have to create a new <Suspense fallback="Loading expense history..." key={expense.id}>
<Await resolve={expenseLogs} errorElement="There was an error loading the expense history. Please try again.">
{(resolvedExpenseLogs) => <ExpenseLogs expenseLogs={resolvedExpenseLogs} />}
</Await>
</Suspense> The Notice that we already do this in Chapter 6, Enhancing the User Experience, where we add a The code for the book was fixed. You can find the change here: 1bbef0c BeforeThe suspense fallback is only shown once when initially navigating to an expense details page. Screen.Recording.2023-12-12.at.8.24.50.PM.movAfterThe suspense fallback is shown on every expense details page navigation. Screen.Recording.2023-12-12.at.8.24.13.PM.mov |
It took me hours to make it work. Your suggestion was indeed very helpful, although for me it didn't work initially. Working example: export default function Thread() {
const loaderData = useLoaderData<typeof loader>();
return (
<>
<Suspense fallback={<div>Loading..</div>} key={useParams().id}>
<Await resolve={loaderData.model}>
{(model) => <>
<div>Loaded {model.id}</div>
</>}
</Await>
</Suspense>
</>
)
} Not working example: export default function Thread() {
const loaderData = useLoaderData<typeof loader>();
return (
<>
<h1>{loaderData.model.name}</h1>
<Suspense fallback={<div>Loading..</div>} key={useParams().id}>
<Await resolve={loaderData.model}>
{(model) => <>
<div>Loaded {model.id}</div>
</>}
</Await>
</Suspense>
</>
)
} As you can see, there is a loader data reference within It may look trivial, but when you have a really big component (or, like me - you're migrating existing components to Suspense/Await logic) and you overlook that, you may be surprised; or - if your loader resolves promises very fast - you may be even unaware that your defer logic doesn't work actually. |
Hey, @nowakrr! What version of Remix are you using, and what does your If |
Hi @andrelandgraf yes, correct. It shouldn't work anyway. Although I think it's worth to mention that your solution DOES work, although, if it does not for some reason, make sure you guys don't have references to the deferred promises outside of Imagine having multiple nested components relaying on the same deferred promise. You need to take care that ALL references to the deferred promise across all nested components are wrapped into
So: all references to the deferred promise must be wrapped inside |
Describe the bug
Deferring expense logs loader data does not work when navigating between expense detail pages.
To Reproduce
Steps to reproduce the behavior:
setTimeout
) theexpenseLogs
database query for better visibility (see p. 247).expenseLogs
data is fetched, not deferring theexpenseLogs
fetch request.Expected behavior
When navigating between expense details pages, the navigation should happen after the
expense
is fetched, but should not await theexpenseLogs
promise. Instead, it should render the expense details page and show the fallback loading indication for theexpenseLogs
section.Actual behavior
The navigation only happens after the
expenseLogs
promise resolves, not deferring the promise.Additional context
When navigating from any other page to an expense details page (e.g., the income routes) or when performing a full-page reload, the deferring of the loader data works as expected. The bug only occurs when navigating between detail pages.
The text was updated successfully, but these errors were encountered: