-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(nuxt): recreate asyncData
when immediate
is disabled
#20980
Conversation
How do I write a test for this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If multiple invocations of useAsyncData
are used (for example, in components) and one is unmounted, this would unset data for the others. It will also lead to the wrong behaviour when we're using payload extraction (for example, on a statically generated site it will remove data from the payload).
How about, instead, re-initialising the value using options.default
when useAsyncData
is called with immediate: false
? (We'll still need to think about whether this is desired behaviour.)
I also thought about using |
- apply only when immediate false or lazy true
@danielroe I was considering where to put the re-installation codes carefully. Could you check that this is okay? Thanks! |
β Live Preview ready!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the approach here, as if the state is shared with another composable it will clear it out.
What about instead updating L124 to:
if (!nuxt._asyncData[key] || !options.immediate) {
That way it would give a 'clean slate' for each new call of the composable but not interfere with other composable calls.
Maybe it would be valuable to add a test to the suite to cover these edge cases, as well as the original issue. Would you be able to add a test as part of the PR?
I tried adding some more conditions at L124 before. If
If I understand correctly, it means BTW, I am not familiar with writing a test. Could you please give me some advice for a test if possible? |
I think at the moment the best way to write a test for this is to do an e2e test in I would make sure to test that data isn't removed from a component that persists (e.g. in a layout) but that 'old' data doesn't persist when re-initialising |
β¦/nuxt into refresh-useAsyncData
β¦ when immediate false`
@danielroe I'm sorry for the late response. I was completely lost because I had a hard time writing a test haha.. I'm not sure this is the right approach. Could you please review? |
immediate
is disabled
immediate
is disabledasyncData
when immediate
is disabled
Thank you β€οΈ |
π Linked issue
#20979
β Type of change
π Description
Resolves #20979
π Checklist