-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
fix(nuxt): update useNuxtData
to access shared asyncData state
#22277
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
Conversation
|
Would you be able to add a regression test? This might be a case for doing so in the unit tests directory (see |
Will do, but I noticed that my implementation only works after hydration and not on the server which may lead to issues. Maybe it's better to change |
It may also resolve this #22348 |
Sorry for the long delay in getting back to you. I don't there's an issue with I'll mark this as draft as it sounds like there's a little more to do here. (And a test would be appreciated.) |
idk, but this does solve issue for me if page is initially loaded (when in case any body wondering, here are changed lines in my patch ( - const getCachedData = () => nuxt.isHydrating ? nuxt.payload.data[key] : nuxt.static.data[key];
- const hasCachedData = () => getCachedData() !== void 0;
+ const getCachedData = () => nuxt.isHydrating ? toRef(nuxt.payload.data, key) : (nuxt.static.data[key] || toRef(nuxt.payload.data, key));
+ const hasCachedData = () => unref(getCachedData()) !== void 0; upd: Now it breaks refetching |
nuxt/nuxt#22277. Dunno, but this does fix my issue
I updated I also included some tests for the synchronization + additional ones for asyncData |
This should also resolve #22696 |
β¦a-nuxtdata-sync
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #22277 +/- ##
=======================================
Coverage ? 58.76%
=======================================
Files ? 5
Lines ? 861
Branches ? 46
=======================================
Hits ? 506
Misses ? 355
Partials ? 0 β View full report in Codecov by Sentry. |
Any idea when this pr will be merged? This would be a good fix and needed I think |
I just fixed the remaining issues, but I'm not sure whether this is the best approach, as it makes all the I also had the idea of splitting Not sure what the better approach is here. Would love to get some feedback on it :) |
@danielroe I hate to do this but any chance we can get this released on the next version? I think this bug should be a higher priority because using useNuxtData without sync does not make sense |
useNuxtData
to access shared asyncData state
π Linked issue
resolves #19704
resolves #22696
β Type of change
π Description
This change synchronizes the data value of
useNuxtData
anduseAsyncData
.Currently, they aren't really in sync. This happens because the data in the payload (used by
useNuxtData
) and asyncData are not the same refs. They're only set to the same values on two occasions:π Checklist