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

Commit 7a316c2

Browse files
authored
fix(nuxt3): include route children in parent suspense (#4422)
1 parent ce38dcb commit 7a316c2

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

  • packages/nuxt3/src/pages/runtime

packages/nuxt3/src/pages/runtime/page.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { defineComponent, h, Suspense, Transition } from 'vue'
1+
import { defineComponent, h, inject, provide, Suspense, Transition } from 'vue'
22
import { RouteLocationNormalizedLoaded, RouterView } from 'vue-router'
33

44
import { generateRouteKey, RouterViewSlotProps, wrapInKeepAlive } from './utils'
55
import { useNuxtApp } from '#app'
66
import { _wrapIf } from '#app/components/utils'
77

8+
const isNestedKey = Symbol('isNested')
9+
810
export default defineComponent({
911
name: 'NuxtPage',
1012
props: {
@@ -16,14 +18,22 @@ export default defineComponent({
1618
setup (props) {
1719
const nuxtApp = useNuxtApp()
1820

21+
const isNested = inject(isNestedKey, false)
22+
provide(isNestedKey, true)
23+
1924
return () => {
2025
return h(RouterView, {}, {
2126
default: (routeProps: RouterViewSlotProps) => routeProps.Component &&
2227
_wrapIf(Transition, routeProps.route.meta.pageTransition ?? defaultPageTransition,
23-
wrapInKeepAlive(routeProps.route.meta.keepalive, h(Suspense, {
24-
onPending: () => nuxtApp.callHook('page:start', routeProps.Component),
25-
onResolve: () => nuxtApp.callHook('page:finish', routeProps.Component)
26-
}, { default: () => h(routeProps.Component, { key: generateRouteKey(props.pageKey, routeProps) } as {}) }))).default()
28+
wrapInKeepAlive(routeProps.route.meta.keepalive,
29+
isNested
30+
// Include route children in parent suspense
31+
? h(routeProps.Component, { key: generateRouteKey(props.pageKey, routeProps) } as {})
32+
: h(Suspense, {
33+
onPending: () => nuxtApp.callHook('page:start', routeProps.Component),
34+
onResolve: () => nuxtApp.callHook('page:finish', routeProps.Component)
35+
}, { default: () => h(routeProps.Component, { key: generateRouteKey(props.pageKey, routeProps) } as {}) })
36+
)).default()
2737
})
2838
}
2939
}

0 commit comments

Comments
 (0)