fix(fetchMenu): fallback to $fetch on client after hydration#461
fix(fetchMenu): fallback to $fetch on client after hydration#461StirStudios wants to merge 2 commits into
Conversation
|
sry for letting this lie so long. @StirStudios Could you clarify why this is needed? usually the menu-fetching should work just fine client-side as well + hydrate properly also? |
|
This fails for us on a full page refresh when used in the admin menu — specifically within the user account menu. Without this in place, the user menu breaks on full page refreshes. |
|
hm, weird. It seems to me that this special-casing is not the proper fix, it adds a work-around to the regular code-path, but why? Could you clarify why the regular fetch is failing in your case? Maybe I'm missing the obvious, but what's wrong with it? How/why does it fail? |
|
Thanks @fago — I think you’re right that the current patch is more of a workaround than the ideal fix. After looking closer, I don’t think the issue is simply “client fetch after hydration.” The more likely issue is that the account menu is session/user-dependent, but useFetchOptions.key = useFetchOptions.key || `menu-${name}`So for the account menu, the SSR result can be cached as: menu-accountThen after a full browser refresh, hydration reuses that cached payload instead of fetching the account menu again with the active browser session. That explains the behavior we see:
So I agree the better fix is probably not a broad client-side For example, instead of always defaulting to: menu-${name}we could support safer behavior for user-dependent menus via an explicit key: await fetchMenu('account', {
key: `menu-account-${currentUserId}`
})Or document that session-dependent menus must provide a cache key that varies by user/session. Another possible fix would be to avoid payload reuse for menus that are known to depend on the active session, but that may be too implicit. So I’m happy to revise this PR away from the hydration |
|
Update after deeper testing on our side: I reverted to a clean baseline and re-tested with local package builds in a real app integration (hard refresh + soft navigation), What we confirmed:
So:
In other words, our earlier comment overstated that cache/key handling was the root cause. It appears to be part of the picture, Happy to continue on a maintainer-preferred direction for a proper module-level fix that preserves normal |
right, that seems to be a needed fix for the case where the user logs in during an active nuxt-instance. But is this even a relevant part for your scenario? As I understand, your account-menu is not correctly populated even on regular SSR page refresh if the user is logged-in. Correct? If we can leave the "react upon user login" case out of the equation for now, that would help to keep things simpler. But that also means the user-ID is not needed as part of the cache-key, assuming we simply to a hard-reload of the whole page after login.
Seems like this is something we need to track down still - the root cause. Why is empty when it should not be. Let's try to find the underlying issue. |
Summary
Why
Scope
Validation