Skip to content

Commit

Permalink
fix(VOverlay): don't render content in ssr
Browse files Browse the repository at this point in the history
fixes #15323
  • Loading branch information
KaelWD committed Dec 13, 2022
1 parent 7adbc22 commit 59d214b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
11 changes: 7 additions & 4 deletions packages/vuetify/src/composables/display.ts
Expand Up @@ -68,6 +68,9 @@ export interface DisplayInstance {
platform: Ref<DisplayPlatform>
thresholds: Ref<DisplayThresholds>

/** @internal */
ssr: boolean

update (): void
}

Expand Down Expand Up @@ -138,13 +141,13 @@ function getPlatform (): DisplayPlatform {
}
}

export function createDisplay (options?: DisplayOptions, isHydrate?: boolean): DisplayInstance {
export function createDisplay (options?: DisplayOptions, ssr?: boolean): DisplayInstance {
const { thresholds, mobileBreakpoint } = parseDisplayOptions(options)

const height = ref(getClientHeight(isHydrate))
const height = ref(getClientHeight(ssr))
const platform = getPlatform()
const state = reactive({} as DisplayInstance)
const width = ref(getClientWidth(isHydrate))
const width = ref(getClientWidth(ssr))

function update () {
height.value = getClientHeight()
Expand Down Expand Up @@ -198,7 +201,7 @@ export function createDisplay (options?: DisplayOptions, isHydrate?: boolean): D
window.addEventListener('resize', update, { passive: true })
}

return { ...toRefs(state), update }
return { ...toRefs(state), update, ssr: !!ssr }
}

export function useDisplay () {
Expand Down
20 changes: 11 additions & 9 deletions packages/vuetify/src/composables/hydration.ts
@@ -1,18 +1,20 @@
// Utilities
import { getCurrentInstance, IN_BROWSER } from '@/util'
import { onMounted, ref } from 'vue'
import { IN_BROWSER } from '@/util'
import { useDisplay } from '@/composables/display'

export function useHydration () {
if (!IN_BROWSER) return ref(false)

const vm = getCurrentInstance('useHydration')
const rootEl = vm?.root?.appContext?.app?._container
const { ssr } = useDisplay()

const isMounted = ref(!!rootEl?.__vue_app__)

if (!isMounted.value) {
onMounted(() => isMounted.value = true)
if (ssr) {
const isMounted = ref(false)
onMounted(() => {
isMounted.value = true
})
return isMounted
} else {
return ref(true)
}

return isMounted
}
3 changes: 2 additions & 1 deletion packages/vuetify/tsconfig.json
Expand Up @@ -16,6 +16,7 @@
"node",
"vue-router"
]
}
},
"stripInternal": true
}
}

0 comments on commit 59d214b

Please sign in to comment.