Skip to content
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

feat(nuxt): reset asyncData to default value when calling clear/clearNuxtData #27295

Merged
merged 23 commits into from
May 22, 2024

Conversation

danielroe
Copy link
Member

🔗 Linked issue

resolves #26269

📚 Description

This changes the default behaviour to reset data.value to the default provided by the user rather than unsetting it entirely to null/undefined.

It's based on top of the branch for #27294 as it overlaps slightly in scope and mechanism for ensuring this is backwards compatible with compatibilityVersion: 3.

@danielroe danielroe self-assigned this May 21, 2024
Copy link

stackblitz bot commented May 21, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@danielroe danielroe changed the title fix(nuxt): use undefined rather than null for data fetching defaults feat(nuxt): reset asyncData to default value when calling clear/clearNuxtData May 21, 2024
@danielroe danielroe changed the base branch from main to fix/undefined-default-value May 21, 2024 18:23
Base automatically changed from fix/undefined-default-value to main May 21, 2024 22:58
@danielroe danielroe marked this pull request as ready for review May 21, 2024 23:12
packages/nuxt/src/app/composables/fetch.ts Outdated Show resolved Hide resolved
packages/nuxt/src/app/composables/fetch.ts Outdated Show resolved Hide resolved
packages/nuxt/src/app/composables/fetch.ts Outdated Show resolved Hide resolved
@@ -333,7 339,7 @@ export function useAsyncData<
return nuxtApp._asyncDataPromises[key]!
}

asyncData.clear = () => clearNuxtDataByKey(nuxtApp, key)
asyncData.reset = asyncData.clear = () => clearNuxtDataByKey(nuxtApp, key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also rename clearNuxtDataByKey to resetNuxtDataByKey?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe part of a bigger question - should we rename clearNuxtData? In fact I am wondering if it would be better to keep clear/clearNuxtData as reset is a change and in most cases the default value is the empty state of the composable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Respect default prop of async data when calling clearNuxtData
2 participants