Retaining previous navigation's data for faster back-navigation + invalidation #2023
Unanswered
Boeing787
asked this question in
Help & Questions
Replies: 2 comments 6 replies
-
@brillout this is what we were chatting about on Discord. Brought into public view so other folks can benefit |
Beta Was this translation helpful? Give feedback.
0 replies
-
Your use case and your approach to implement it sounds good to me.
What Vike version are you using? The |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context:
UX Expectation #1:
We are building a social feed -- the feed is made up of a list of posts, and clicking on a post takes you to the post page. Navigating back to the main feed, the user expects to return to the feed from which they originally came.
UX Expectation #2:
Many social platforms want to maintain a feed that feels fresh, so every time new posts are intentionally requested or you refresh the page, the set of posts are always different.
Our app:
Right now, our Vike app fires preloaded queries on every page navigation, forward or backward. This has been fine until now...but our feed works the same way: when the feed query is fired, it always returns new posts. This means that when a user navigates back to the feed from a post page, the preloaded feed query fires, and they are returned to a completely different feed than the one from which they came earlier. This goes against UX Expectation #1.
What we've done so far:
On our end, we implemented previous navigation preloaded caching in +onRenderClient and +onBeforeRender, which is working great. Now, returning from the post page to the original feed loads the preloaded query data from the previous navigation's cache, and the user is returned to right where they expected, seeing the original data.
Where we need advice
There are still instances in our application where we want to bust the previous navigation preloaded query cache. Example: when you make a payment on our platform, and you navigate back to the payments page, you should see your new payment -- this data should be refetched. This is something we would want to control per-navigation. We are using client-side navigation.
How would you do it?
Attempt at solution
I thought about adding a custom parameter to
pageContext
, and then invalidating the cache in +onRenderClient and +onBeforeRender based on whether that parameter is present.The documentation suggests passing custom pageContext parameters to
navigate
fromvike/client
-- like this:This doesn't seem to work...anything passed here isn't available in
pageContext
throughout the app. 🐛 ?Ideally, we would do something like
navigate('/some/url', { pageContext: { invalidatePreloadedQueryCache: true } })
, but curious if there are any other thoughts!Beta Was this translation helpful? Give feedback.
All reactions