undefined default value of data
is the
undefined default value of data in useAsyncData() a Nuxt 4 feature? Or is it backwards compat with Nuxt 3?2 Replies
Hi @Donald Biden. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, the
undefined default value for data in useAsyncData() is a Nuxt 4 feature, but it has been backported to Nuxt 3 as an opt-in change.
Nuxt 4 Behavior
In Nuxt 4, data and error objects returned from useAsyncData default to undefined. According to the Nuxt 4 upgrade guide, this change was made for greater consistency, as previously data was initialized to null but reset in clearNuxtData to undefined.
Nuxt 3 Compatibility
In Nuxt 3, the default behavior is still null for both data and error. However, you can opt into the Nuxt 4 behavior in Nuxt 3. According to the Nuxt 3 upgrade guide, if you encounter issues with the new undefined default, you can revert to the previous behavior with:
This configuration option suggests that the undefined default can be enabled in Nuxt 3 as an experimental feature, but it's the standard behavior in Nuxt 4.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1214688654199496797> Kapa.ai is still learning and improving, please let me know how I did by reacting below.