Skip to content
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: 6 additions & 4 deletions packages/hub-ui/src/client/components/dock/Dock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import type { DocksContext } from '@devframes/hub/client'
import type { CSSProperties } from 'vue'
import type { DockLayout } from './dock-layout'
import { useEventListener, useScreenSafeArea, whenever } from '@vueuse/core'
import { useEventListener, whenever } from '@vueuse/core'
import { computed, onMounted, reactive, ref, useTemplateRef, watch } from 'vue'
import { BUILTIN_ENTRY_CLIENT_AUTH_NOTICE } from '../../constants'
import { t } from '../../i18n'
import { docksSplitGroupsWithCapacity, getEntryGroup, resolveNextRecentDockIds, resolveRecentDockEntries } from '../../state/dock-settings'
import { setDocksOverflowPanel, useDocksGroupPanel } from '../../state/floating-tooltip'
import { useSettings } from '../../state/settings-defaults'
import { useIsRpcTrusted } from '../../utils/useIsRpcTrusted'
import { useSafeArea } from '../../utils/useSafeArea'
import BrandMark from '../icons/BrandMark.vue'
import {
dockLayoutCssVars,
Expand Down Expand Up @@ -39,10 +40,12 @@ const layout = computed(() => resolveDockLayout(props.layout))

const isSafari = navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome')

const safeArea = useScreenSafeArea()
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')

const safeArea = useSafeArea(anchorEl)

function toNumber(value: string) {
const num = +value
const num = Number.parseFloat(value)
if (Number.isNaN(num))
return 0
return num
Expand All @@ -61,7 +64,6 @@ const panelMargins = computed(() => resolveViewportMargins(
))

const dockEl = useTemplateRef<HTMLDivElement>('dockEl')
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')

const recalculateCounter = ref(0)
const isHovering = ref(false)
Expand Down
4 changes: 4 additions & 0 deletions packages/hub-ui/src/client/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
--app-scrollbar-radius: 1px;
--app-scrollbar-thumb: #8884;
--app-scrollbar-thumb-hover: #8885;
--devframes-safe-area-top: env(safe-area-inset-top, 0px);
--devframes-safe-area-right: env(safe-area-inset-right, 0px);
--devframes-safe-area-bottom: env(safe-area-inset-bottom, 0px);
--devframes-safe-area-left: env(safe-area-inset-left, 0px);
}

::-webkit-scrollbar {
Expand Down
30 changes: 30 additions & 0 deletions packages/hub-ui/src/client/utils/useSafeArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { MaybeElementRef } from '@vueuse/core'
import { tryOnMounted, unrefElement, useDebounceFn, useEventListener } from '@vueuse/core'
import { shallowRef } from 'vue'

/**
* Ported from VueUse's `useScreenSafeArea` for now: it always sets its CSS variables on
* `<html>` and has no option for a custom element, which breaks hydration on SSR hosts.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antfu I wasn't sure about this part, so I added this "port" to suggest whether this addition should be added to VueUse, didn't want to make too many decisions, do let me know if this is even a good direction, or:

  1. Port back the fix to VueUse
  2. Remove the safeArea usage all together? probably not
  3. Close PR and accept the warning and have the users manually import the Dock

*/
export function useSafeArea(target: MaybeElementRef) {
const top = shallowRef('')
const right = shallowRef('')
const bottom = shallowRef('')
const left = shallowRef('')

function update() {
const element = unrefElement(target)
if (!element)
return
const style = getComputedStyle(element)
top.value = style.getPropertyValue('--devframes-safe-area-top')
right.value = style.getPropertyValue('--devframes-safe-area-right')
bottom.value = style.getPropertyValue('--devframes-safe-area-bottom')
left.value = style.getPropertyValue('--devframes-safe-area-left')
}

tryOnMounted(update)
useEventListener('resize', useDebounceFn(update), { passive: true })

return { top, right, bottom, left, update }
}
Loading