Skip to content

Commit

Permalink
fix(layout): use suspense to delay render of layout items
Browse files Browse the repository at this point in the history
closes #15202
  • Loading branch information
nekosaur committed Jun 8, 2022
1 parent 9655be4 commit 7d12980
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 158 deletions.
7 changes: 6 additions & 1 deletion packages/vuetify/src/components/VApp/VApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { createLayout, makeLayoutProps } from '@/composables/layout'
// Utilities
import { defineComponent, useRender } from '@/util'
import { useRtl } from '@/composables/rtl'
import { Suspense } from 'vue'

export const VApp = defineComponent({
name: 'VApp',
Expand Down Expand Up @@ -35,7 +36,11 @@ export const VApp = defineComponent({
data-app="true"
>
<div class="v-application__wrap">
{ slots.default?.() }
<Suspense>
<>
{ slots.default?.() }
</>
</Suspense>
</div>
</div>
))
Expand Down
12 changes: 7 additions & 5 deletions packages/vuetify/src/components/VAppBar/VAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { computed, ref, toRef } from 'vue'
import { defineComponent } from '@/util'
import { defineComponent, useRender } from '@/util'

// Types
import type { PropType } from 'vue'
Expand Down Expand Up @@ -53,12 +53,12 @@ export const VAppBar = defineComponent({
const vToolbarRef = ref()
const isActive = useProxiedModel(props, 'modelValue')
const height = computed(() => {
const height: number = vToolbarRef.value?.contentHeight ?? 0
const height: number = vToolbarRef.value?.contentHeight ?? props.height
const extensionHeight: number = vToolbarRef.value?.extensionHeight ?? 0

return (height + extensionHeight)
})
const { layoutItemStyles } = useLayoutItem({
const { layoutItemStyles, layoutIsReady } = useLayoutItem({
id: props.name,
order: computed(() => parseInt(props.order, 10)),
position: toRef(props, 'location'),
Expand All @@ -68,7 +68,7 @@ export const VAppBar = defineComponent({
absolute: toRef(props, 'absolute'),
})

return () => {
useRender(() => {
const [toolbarProps] = filterToolbarProps(props)

return (
Expand All @@ -88,7 +88,9 @@ export const VAppBar = defineComponent({
v-slots={ slots }
/>
)
}
})

return layoutIsReady
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { computed, toRef } from 'vue'
import { convertToUnit, defineComponent } from '@/util'
import { convertToUnit, defineComponent, useRender } from '@/util'

// Types
import { VBtnToggleSymbol } from '../VBtnToggle/VBtnToggle'
Expand Down Expand Up @@ -67,7 +67,7 @@ export const VBottomNavigation = defineComponent({
(props.density === 'compact' ? 16 : 0)
))
const isActive = useProxiedModel(props, 'modelValue', props.modelValue)
const { layoutItemStyles } = useLayoutItem({
const { layoutItemStyles, layoutIsReady } = useLayoutItem({
id: props.name,
order: computed(() => parseInt(props.order, 10)),
position: computed(() => 'bottom'),
Expand All @@ -88,7 +88,7 @@ export const VBottomNavigation = defineComponent({
},
}, { scoped: true })

return () => {
useRender(() => {
return (
<props.tag
class={[
Expand Down Expand Up @@ -121,7 +121,9 @@ export const VBottomNavigation = defineComponent({
) }
</props.tag>
)
}
})

return layoutIsReady
},
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference types="../../../../types/cypress" />

import { VLayout } from '@/components/VLayout'
import { VBottomNavigation } from '../VBottomNavigation'

describe('VBottomNavigation', () => {
it('should not be visible if modelValue is false', () => {
cy.mount(() => (
<VLayout>
<VBottomNavigation modelValue={false}></VBottomNavigation>
</VLayout>
))

cy.get('.v-bottom-navigation').should('not.be.visible')
})
})

This file was deleted.

This file was deleted.

10 changes: 6 additions & 4 deletions packages/vuetify/src/components/VFooter/VFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useResizeObserver } from '@/composables/resizeObserver'

// Utilities
import { computed, ref, toRef } from 'vue'
import { defineComponent } from '@/util'
import { defineComponent, useRender } from '@/util'

export const VFooter = defineComponent({
name: 'VFooter',
Expand Down Expand Up @@ -47,7 +47,7 @@ export const VFooter = defineComponent({
autoHeight.value = entries[0].target.clientHeight
})
const height = computed(() => props.height === 'auto' ? autoHeight.value : parseInt(props.height, 10))
const { layoutItemStyles } = useLayoutItem({
const { layoutItemStyles, layoutIsReady } = useLayoutItem({
id: props.name,
order: computed(() => parseInt(props.order, 10)),
position: computed(() => 'bottom'),
Expand All @@ -57,7 +57,7 @@ export const VFooter = defineComponent({
absolute: toRef(props, 'absolute'),
})

return () => (
useRender(() => (
<props.tag
ref={ resizeRef }
class={[
Expand All @@ -74,6 +74,8 @@ export const VFooter = defineComponent({
]}
v-slots={ slots }
/>
)
))

return props.app ? layoutIsReady : {}
},
})
13 changes: 9 additions & 4 deletions packages/vuetify/src/components/VLayout/VLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Styles
import './VLayout.sass'

// Utilities
import { defineComponent, useRender } from '@/util'

// Composables
import { createLayout, makeLayoutProps } from '@/composables/layout'

// Utilities
import { Suspense } from 'vue'
import { defineComponent, useRender } from '@/util'

export const VLayout = defineComponent({
name: 'VLayout',

Expand All @@ -17,7 +18,11 @@ export const VLayout = defineComponent({

useRender(() => (
<div ref={ layoutRef } class={ layoutClasses.value } style={ layoutStyles.value }>
{ slots.default?.() }
<Suspense>
<>
{ slots.default?.() }
</>
</Suspense>
</div>
))

Expand Down
10 changes: 6 additions & 4 deletions packages/vuetify/src/components/VMain/VMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { useLayout } from '@/composables/layout'
import { useSsrBoot } from '@/composables/ssrBoot'

// Utilities
import { defineComponent } from '@/util'
import { defineComponent, useRender } from '@/util'

export const VMain = defineComponent({
name: 'VMain',

props: makeTagProps({ tag: 'main' }),

setup (props, { slots }) {
const { mainStyles } = useLayout()
const { mainStyles, layoutIsReady } = useLayout()
const { ssrBootStyles } = useSsrBoot()

return () => (
useRender(() => (
<props.tag
class="v-main"
style={[
Expand All @@ -30,6 +30,8 @@ export const VMain = defineComponent({
{ slots.default?.() }
</div>
</props.tag>
)
))

return layoutIsReady
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { useSsrBoot } from '@/composables/ssrBoot'
import { useTouch } from './touch'

// Utilities
import { computed, onBeforeMount, ref, toRef, Transition, watch } from 'vue'
import { convertToUnit, defineComponent } from '@/util'
import { computed, ref, toRef, Transition, watch } from 'vue'
import { convertToUnit, defineComponent, useRender } from '@/util'

// Types
import type { PropType } from 'vue'
Expand Down Expand Up @@ -96,11 +96,9 @@ export const VNavigationDrawer = defineComponent({
if (val) isActive.value = true
})

onBeforeMount(() => {
if (props.modelValue != null || isTemporary.value) return

if (props.modelValue == null && !isTemporary.value) {
isActive.value = props.permanent || !mobile.value
})
}

const rootEl = ref<HTMLElement>()

Expand All @@ -119,7 +117,7 @@ export const VNavigationDrawer = defineComponent({

return isDragging.value ? size * dragProgress.value : size
})
const { layoutItemStyles, layoutRect, layoutItemScrimStyles } = useLayoutItem({
const { layoutItemStyles, layoutRect, layoutItemScrimStyles, layoutIsReady } = useLayoutItem({
id: props.name,
order: computed(() => parseInt(props.order, 10)),
position: toRef(props, 'location'),
Expand All @@ -144,7 +142,7 @@ export const VNavigationDrawer = defineComponent({
...layoutItemScrimStyles.value,
}))

return () => {
useRender(() => {
const hasImage = (slots.image || props.image)

return (
Expand Down Expand Up @@ -217,7 +215,9 @@ export const VNavigationDrawer = defineComponent({
</Transition>
</>
)
}
})

return layoutIsReady
},
})

Expand Down
Loading

0 comments on commit 7d12980

Please sign in to comment.