Skip to content
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

fix(VAppBar): vertical main layout shift on SSR request #20563

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/vuetify/src/components/VAppBar/VAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import './VAppBar.sass'

// Components
import { makeVToolbarProps, VToolbar } from '@/components/VToolbar/VToolbar'
import { calculateHeight, makeVToolbarProps, VToolbar } from '@/components/VToolbar/VToolbar'

// Composables
import { makeLayoutItemProps, useLayoutItem } from '@/composables/layout'
Expand Down Expand Up @@ -108,8 +108,12 @@ export const VAppBar = genericComponent<VToolbarSlots>()({
const height = computed(() => {
if (scrollBehavior.value.hide && scrollBehavior.value.inverted) return 0

const height = vToolbarRef.value?.contentHeight ?? 0
const extensionHeight = vToolbarRef.value?.extensionHeight ?? 0
const height = vToolbarRef.value?.contentHeight ?? calculateHeight(props.height, props.density, false)
const extensionHeight = vToolbarRef.value?.extensionHeight ??
(props.extended || slots.extension?.()
? calculateHeight(props.extensionHeight, props.density, true)
: 0
)

if (!canHide.value) return (height + extensionHeight)

Expand Down
27 changes: 15 additions & 12 deletions packages/vuetify/src/components/VToolbar/VToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export const makeVToolbarProps = propsFactory({
...makeThemeProps(),
}, 'VToolbar')

export function calculateHeight (height: number | string, density: Density, forExtensionHeight: boolean) {
return parseInt((
Number(height) +
(density === 'prominent' ? Number(height) : 0) -
(density === 'comfortable' ? forExtensionHeight ? 4 : 8 : 0) -
(density === 'compact' ? forExtensionHeight ? 8 : 16 : 0)
), 10)
}

export type VToolbarSlots = {
default: never
image: never
Expand All @@ -83,19 +92,13 @@ export const VToolbar = genericComponent<VToolbarSlots>()({
const { rtlClasses } = useRtl()

const isExtended = shallowRef(!!(props.extended || slots.extension?.()))
const contentHeight = computed(() => parseInt((
Number(props.height) +
(props.density === 'prominent' ? Number(props.height) : 0) -
(props.density === 'comfortable' ? 8 : 0) -
(props.density === 'compact' ? 16 : 0)
), 10))
const contentHeight = computed(() => calculateHeight(
props.height,
props.density,
false,
))
const extensionHeight = computed(() => isExtended.value
? parseInt((
Number(props.extensionHeight) +
(props.density === 'prominent' ? Number(props.extensionHeight) : 0) -
(props.density === 'comfortable' ? 4 : 0) -
(props.density === 'compact' ? 8 : 0)
), 10)
? calculateHeight(props.extensionHeight, props.density, true)
: 0
)

Expand Down