Support loader return differentiation based on revalidation state #4774
Replies: 2 comments 1 reply
-
Remix already has a const isRevalidating = request.headers.get('X-Remix-Revalidate') === 'yes' remix/packages/remix-server-runtime/server.ts Lines 107 to 116 in ef26f76 |
Beta Was this translation helpful? Give feedback.
-
Hello everyone! 😊 I hope you're all having a fantastic day! I was wondering if there are any updates on this topic. I've come across a use case that I'd like to share, and I'm curious to hear your thoughts on how to approach it. Let's say we have a shopping basket icon located at the top right corner of a webpage. We want to fetch the items count in the basket via the loader from the client side to enable CDN's page cache. I've been considering a couple of options, and I'd appreciate any feedback or suggestions you might have.
Best regards, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
You can find my use case explanation in this live stream at around 1:10:00 ish.
Let's say you've got a combobox and you want to pre-fill it with some data. So you have an
initialData
property in the json you return for the loader. However, when there's revalidation for that route, the combobox doesn't need theinitialData
anymore because it already got it on the initial route load, so returninginitialData
is unnecessary (and sub-optimal).I'd like a way for the loader to know whether the call is a result of loader revalidation.
@ryanflorence suggested using the
referer
header and I think when React Router 6.4 is finished integrating with Remix that may work. In this case, the fetch will be called from the route that the user is navigating from and the loader could simply do something like this:I think this should work, however Ryan seemed to think a
X-Remix-Referrer
would be necessary.EDIT: FWIW, this won't work on LiveReload because the referrer in that case is the page you were on when the live reload happened.
Suggestions and ideas are welcome. Kinda tricky because I won't really be able to test this fully until React Router 6.4 is fully integrated with Remix.
Beta Was this translation helpful? Give feedback.
All reactions