-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
useFetch triggers a request on the client side in nested components (using resolveComponent) #20476
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
Comments
As I understand, "behind the scenes" you use defineAsyncComponent to register the component as an async component and it gets separated into its own chunk (here is an example replacing resolveComponent with defineAsyncComponent from the previous example). When the chunk is loaded on the client, data from the useFetch somehow doesn't get transferred although it exists in the payload, and a new request is then triggered. Here's a workaround, which doesn't seem right 😄 Do you have any other ideas or workarounds on how to achieve this without triggering the request on the client? I know there are several ways to use a component, but none of them seem to work if you use them in the inner/nested component. <component :is="component" />
<script setup>
const component = resolveComponent('Main')
// or
const component = defineAsyncComponent(() => import('../Main.vue'))
</script> <Main />
<script setup>
const component = 'Main'
// or
const Main = resolveComponent('Main')
// or
const Main = defineAsyncComponent(() => import('../Main.vue'))
</script> |
With further "investigation", I concluded that the inner/nested component somehow doesn't hydrate. const getCachedData = () => nuxt.payload.data[key] || nuxt.static.data[key] Another "fix" would be to set useNuxtApp().isHydrating = process.client At the end (after many edits of the comment 🙂), I think that all comes down to the |
The root issue here is an upstream Vue bug with hydrating async components: vuejs/core#6638. We can track within the Nuxt repository via #18405. |
Environment
Reproduction
https://stackblitz.com/edit/nuxt-starter-6ejkfx?file=pages/variable.vue
Describe the bug
This issue happens when you use nested
<component :is="component" />
If you resolve the parent component with the string - useFetch triggers a request only on the server side and the data is transferred to the client, which is fine.
If you resolve the parent component with the variable, everything renders well, but useFech triggers a request both on the server side and the client side
Components are registered as global components as it was mentioned here.
Additional context
There is an index.vue page in the stackblitz example where everything works fine, and variable.vue which is "broken".
Logs
No response
The text was updated successfully, but these errors were encountered: