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

fix(nuxt): refetch both undefined/null values in useAsyncData #23351

Merged
merged 7 commits into from Oct 16, 2023

Conversation

warflash
Copy link
Member

@warflash warflash commented Sep 22, 2023

πŸ”— Linked issue

Resolves #23349
Resolves #22696

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This ensures nuxt payload data is checked against null and undefined values in the (hopefully) least breaking way possible.
When useNuxtData is called before a client side useAsyncData call is resolved, useNuxtDatawill set the value of the key to null. hasCachedData so far only checked for undefined values so null would pass and be returned, both for the useAsyncData and useNuxtData.
I feel like this is not the cleanest way to go about this, setting they key to undefined like clearNuxtData does might be more concise. However then the return signature of useNuxtData => <DataT | undefined> might break existing user logic.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Sep 22, 2023

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

@warflash warflash changed the title fix(nuxt): fix how 'hasCachedData' is determined [#23349] fix(nuxt): fix how 'hasCachedData' is determined Sep 22, 2023
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

Would you be able to add a regression test to cover the situation in the linked issue? πŸ™

We can then look at fixing the currently failing tests.

@danielroe danielroe changed the title fix(nuxt): fix how 'hasCachedData' is determined fix(nuxt): refetch both undefined/null values in useAsyncData Oct 16, 2023
@danielroe danielroe merged commit f4d67a9 into nuxt:main Oct 16, 2023
35 checks passed
@github-actions github-actions bot mentioned this pull request Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants