Skip to content

Commit 47ca623

Browse files
omridevkclaude
andcommitted
fix(hub-ui): keep dock safe-area variables off <html>
useScreenSafeArea sets its CSS variables on <html>, which React SSR hosts hydrate themselves, so loading the dock logs a hydration mismatch. Port it as useSafeArea(target): the variables live in the dock stylesheet :host and are read back from the dock anchor. Also parse the insets with parseFloat, since values like "34px" made the unary plus return NaN, so insets were 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 415a307 commit 47ca623

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎packages/hub-ui/src/client/components/dock/Dock.vue‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import type { DocksContext } from '@devframes/hub/client'
33
import type { CSSProperties } from 'vue'
44
import type { DockLayout } from './dock-layout'
5-
import { useEventListener, useScreenSafeArea, whenever } from '@vueuse/core'
5+
import { useEventListener, whenever } from '@vueuse/core'
66
import { computed, onMounted, reactive, ref, useTemplateRef, watch } from 'vue'
77
import { BUILTIN_ENTRY_CLIENT_AUTH_NOTICE } from '../../constants'
88
import { t } from '../../i18n'
99
import { docksSplitGroupsWithCapacity, getEntryGroup, resolveNextRecentDockIds, resolveRecentDockEntries } from '../../state/dock-settings'
1010
import { setDocksOverflowPanel, useDocksGroupPanel } from '../../state/floating-tooltip'
1111
import { useSettings } from '../../state/settings-defaults'
1212
import { useIsRpcTrusted } from '../../utils/useIsRpcTrusted'
13+
import { useSafeArea } from '../../utils/useSafeArea'
1314
import BrandMark from '../icons/BrandMark.vue'
1415
import {
1516
dockLayoutCssVars,
@@ -39,10 +40,12 @@ const layout = computed(() => resolveDockLayout(props.layout))
3940
4041
const isSafari = navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')
4142
42-
const safeArea = useScreenSafeArea()
43+
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')
44+
45+
const safeArea = useSafeArea(anchorEl)
4346
4447
function toNumber(value: string) {
45-
const num = +value
48+
const num = Number.parseFloat(value)
4649
if (Number.isNaN(num))
4750
return 0
4851
return num
@@ -61,7 +64,6 @@ const panelMargins = computed(() => resolveViewportMargins(
6164
))
6265
6366
const dockEl = useTemplateRef<HTMLDivElement>('dockEl')
64-
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')
6567
6668
const recalculateCounter = ref(0)
6769
const isHovering = ref(false)

‎packages/hub-ui/src/client/style.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
--app-scrollbar-radius: 1px;
2929
--app-scrollbar-thumb: #8884;
3030
--app-scrollbar-thumb-hover: #8885;
31+
--devframes-safe-area-top: env(safe-area-inset-top, 0px);
32+
--devframes-safe-area-right: env(safe-area-inset-right, 0px);
33+
--devframes-safe-area-bottom: env(safe-area-inset-bottom, 0px);
34+
--devframes-safe-area-left: env(safe-area-inset-left, 0px);
3135
}
3236

3337
::-webkit-scrollbar {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { MaybeElementRef } from '@vueuse/core'
2+
import { tryOnMounted, unrefElement, useDebounceFn, useEventListener } from '@vueuse/core'
3+
import { shallowRef } from 'vue'
4+
5+
/**
6+
* Ported from VueUse's `useScreenSafeArea` for now: it always sets its CSS variables on
7+
* `<html>` and has no option for a custom element, which breaks hydration on SSR hosts.
8+
*/
9+
export function useSafeArea(target: MaybeElementRef) {
10+
const top = shallowRef('')
11+
const right = shallowRef('')
12+
const bottom = shallowRef('')
13+
const left = shallowRef('')
14+
15+
function update() {
16+
const element = unrefElement(target)
17+
if (!element)
18+
return
19+
const style = getComputedStyle(element)
20+
top.value = style.getPropertyValue('--devframes-safe-area-top')
21+
right.value = style.getPropertyValue('--devframes-safe-area-right')
22+
bottom.value = style.getPropertyValue('--devframes-safe-area-bottom')
23+
left.value = style.getPropertyValue('--devframes-safe-area-left')
24+
}
25+
26+
tryOnMounted(update)
27+
useEventListener('resize', useDebounceFn(update), { passive: true })
28+
29+
return { top, right, bottom, left, update }
30+
}

0 commit comments

Comments
 (0)