Skip to content

Commit b58a2f4

Browse files
omridevkclaudeantfubotantfu
authored
fix(hub-ui): keep dock safe-area variables off <html> (#483)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Anthony Fu (via agent) <reg-github-bot@antfu.me> Co-authored-by: Anthony Fu <github@antfu.me>
1 parent c47fdea commit b58a2f4

3 files changed

Lines changed: 45 additions & 18 deletions

File tree

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

Lines changed: 5 additions & 18 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,29 +40,15 @@ 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')
4344
44-
function toNumber(value: string) {
45-
const num = +value
46-
if (Number.isNaN(num))
47-
return 0
48-
return num
49-
}
45+
const safeArea = useSafeArea(anchorEl)
5046
5147
// Effective spacing from the viewport edge: device safe-area insets plus the
5248
// configured viewport margin. Passed down to the panel so both stay in sync.
53-
const panelMargins = computed(() => resolveViewportMargins(
54-
{
55-
left: toNumber(safeArea.left.value),
56-
top: toNumber(safeArea.top.value),
57-
right: toNumber(safeArea.right.value),
58-
bottom: toNumber(safeArea.bottom.value),
59-
},
60-
layout.value,
61-
))
49+
const panelMargins = computed(() => resolveViewportMargins(safeArea.value, layout.value))
6250
6351
const dockEl = useTemplateRef<HTMLDivElement>('dockEl')
64-
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')
6552
6653
const recalculateCounter = ref(0)
6754
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { MaybeElementRef } from '@vueuse/core'
2+
import type { DockMargins } from '../components/dock/dock-layout'
3+
import { tryOnMounted, unrefElement, useDebounceFn, useEventListener } from '@vueuse/core'
4+
import { shallowRef } from 'vue'
5+
6+
/**
7+
* Ported from VueUse's `useScreenSafeArea` for now: it always sets its CSS variables on
8+
* `<html>` and has no option for a custom element, which breaks hydration on SSR hosts.
9+
* Reads the `--devframes-safe-area-*` variables (see `style.css`) from `target`, in px.
10+
*/
11+
export function useSafeArea(target: MaybeElementRef) {
12+
const insets = shallowRef<DockMargins>({ top: 0, right: 0, bottom: 0, left: 0 })
13+
14+
function read(style: CSSStyleDeclaration, side: keyof DockMargins) {
15+
// The computed value is a length such as `34px`, so parse it as a float.
16+
return Number.parseFloat(style.getPropertyValue(`--devframes-safe-area-${side}`)) || 0
17+
}
18+
19+
function update() {
20+
const element = unrefElement(target)
21+
if (!element)
22+
return
23+
const style = getComputedStyle(element)
24+
insets.value = {
25+
top: read(style, 'top'),
26+
right: read(style, 'right'),
27+
bottom: read(style, 'bottom'),
28+
left: read(style, 'left'),
29+
}
30+
}
31+
32+
tryOnMounted(update)
33+
useEventListener('resize', useDebounceFn(update), { passive: true })
34+
35+
return insets
36+
}

0 commit comments

Comments
 (0)