Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxt3): fix layout suspense loading #3670

Merged
merged 1 commit into from
Mar 15, 2022
Merged

fix(nuxt3): fix layout suspense loading #3670

merged 1 commit into from
Mar 15, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves nuxt/nuxt#13168, resolves nuxt/nuxt#13369

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 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)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This resolves two significant layout-related bugs. By setting suspensible to false, layout children weren't blocking rendering of the app, which meant that isHydrating was false by the time these functions ran.

There is still an upstream bug related to nested suspenses on route changes, but it has a different cause.

πŸ“ Checklist

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

@danielroe danielroe added bug Something isn't working nuxt3 ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf labels Mar 15, 2022
@danielroe danielroe requested a review from pi0 March 15, 2022 11:15
@danielroe danielroe self-assigned this Mar 15, 2022
@netlify
Copy link

netlify bot commented Mar 15, 2022

βœ”οΈ Deploy Preview for nuxt3-docs canceled.

πŸ”¨ Explore the source changes: 4a42cdd

πŸ” Inspect the deploy log: https://app.netlify.com/sites/nuxt3-docs/deploys/62307546c24306000842b790

@pi0 pi0 merged commit 3e0a3ed into main Mar 15, 2022
@pi0 pi0 deleted the fix/layout-suspense branch March 15, 2022 11:22
Copy link
Member

atinux commented Mar 15, 2022

Thank you @danielroe

@tiborpino
Copy link

tiborpino commented Mar 23, 2022

After Nuxt 3.0.0-27335375.b41a1d2 upgrade double calling is fixed, but there is another error.
Data fetch with useLazyFetch are available on the server side but not on the client side. Data on the client side are always null. Watch doesn't help, it never runs.

const { data: cart } = await useLazyFetch<any>('/api/cart', {
    headers: useRequestHeaders(['cookie']),
})
if (process.server) {
    console.log('server: ', cart.value) // data available
}
if (process.client) {
    console.log('client: ', cart.value) // data null
}
watch(cart.value, (updatedCart) => {
    console.log('watch: ', updatedCart) // never runs
})

without await

const { data: cart } = useLazyFetch<any>('/api/cart', {
    headers: useRequestHeaders(['cookie']),
})
if (process.server) {
    console.log('server: ', cart.value) // data null
}
if (process.client) {
    console.log('client: ', cart.value) // data null
}
watch(cart.value, (updatedCart) => {
    console.log('watch: ', updatedCart) // never runs
})

@danielroe
Copy link
Member Author

@tiborpino The syntax is

watch(() => cart.value, (updatedCart) => {
    console.log('watch: ', updatedCart)
})

The issue about data not being preset on client-side looks like a separate issue - let's track on nuxt/nuxt#13560.

@tiborpino
Copy link

tiborpino commented Mar 23, 2022

Now I'm using useLazyAsyncData as replacent for useLazyFetch because of the bug nuxt/nuxt#13560 and watch still doesn't work

const cart = useLazyAsyncData('cart', () =>
    $fetch('/api/cart', {
        headers: useRequestHeaders(['cookie']),
    })
)
watch(
    () => cart.data.value,
    (updatedCart) => {
        console.log('watch: ', updatedCart) // never runs
    }
)

@danielroe
Copy link
Member Author

Let's track in that issue (or another, if you think it's a new one). This is a merged PR that is unrelated.

@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x bug Something isn't working nuxt3 ❗ p4-important Priority 4: bugs that violate documented behavior, or significantly impact perf
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useAsyncData and useFetch run twice if page uses layout useAsyncData can't block render layouts
4 participants