-
-
Notifications
You must be signed in to change notification settings - Fork 1k
fix(nuxt): reuse asyncData
promise with existing key
#5078
Conversation
asyncData
promise with existing key
On further inspection this fix is a bit wonky, bear with |
@cherrymarker Oops, sorry, missed your comment. Will hold any further comments for now. |
While this fix "sort of" works, I have realised due to this line there may be problems
The original asyncdata is still passed along. A better solution would be to store the asyncData, and fetch it later IF the promise has already been found. |
Updated to a better solution that works both client and server side. Wasn't sure about the type definition in |
β Deploy Preview for nuxt3-docs canceled.
|
I wonder if this would be an opportunity to share asyncData across calls, which would also address a related issue where |
I think that the design of useAsyncData is a bit messy and could be simplified by just using async methods. Instead of I think instead of having pending as a bool, a Promise that resolves when the handler is finished is far more useful and easier to use. |
What do you have in mind?
This makes sense since it will keep the scope of each one (
Not 100% sure about this since most people use |
Hi @cherrymarker thanks for PR and sorry it took long to review. We are iterating over this issue to fix related issues. Please check #5738 (comment) for a summary of changes and plans opened so far. Feel free to try changes and share feedbacks via issue for any suggestions. |
π Linked issue
nuxt/nuxt#13910
β Type of change
I suppose this is technically a breaking change if applications are dependant on the original broken behaviour.
π Description
I have modified useAsyncData to return the correct data (the original asyncdata from the first call) associated with a request in the case that another call is made to useAsyncData while the original promise is still pending.
This change allows you to call useAsyncData on a single key, within multiple components, and work with the data on the server side without subsequent calls resolving to pending and null.
Resolves nuxt/nuxt#13910 for now, more robust solution required in future.
π Checklist