fix(nuxt): await nuxt ready state before refreshNuxtData
#21008
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
π Linked issue
n/a, internal mention: https://discord.com/channels/473401852243869706/1065634249174159420/1108033633870155836
β Type of change
π Description
This PRs aims at improving the DX of Nuxt utils by enforcing relevant utils to await Nuxt ready state before performing their actions. Basically, it ensures and simplifies the following kind of workflows:
Indeed, some utils can have unexpected behavior when launched prior and/or during Nuxt initialization process. For example,
refreshNuxtData()
, when called from a plugin during Nuxt initialization process cannot refresh all Nuxt data properly because Nuxt data lifecycles are still in the process of being resolved. Awaiting for Nuxt to be initialized is almost mandatory if we want this util to work consistently.Considered utils
So far, really, this PR only applies to
refreshNuxtData()
, I tried to consider utils alike.abortNavigation
, can only be used inside route middlewaresclearError
, can't think of a scenario where this would make senseclearNuxtData
, if there's no data to clear, there's no data to clear(?)navigateTo
, maybe it applies to this one(?) not sureThat being said, if you see other utils where waiting for
onNuxtReady
seems mandatory, please voice it! Happy to update the PR.Doing nothing
I've been torn a bit on whether or not we should bake in the
onNuxtReady
call. Basically: should we consider it a DX feature (having both separated) or a DX bug (what this PR fixes)I'm leaning towards a DX bug hence this PR, but happy to reconsider it and close the PR if we settle on a DX feature (forcing explicit
onNuxtReady
calls where applicable)Let me know if anything~
π Checklist