Skip to content

Commit d45f7f3

Browse files
committed
refactor: gate DOM probes behind IN_BROWSER
PHILOSOPHY §2.10 — four sites across useHotkey, useClickOutside, createCombobox, and SelectRoot. Returns false/null under SSR; all consumers handle those values cleanly.
1 parent 36d8cff commit d45f7f3

4 files changed

Lines changed: 13 additions & 2 deletions

File tree

packages/0/src/components/Select/SelectRoot.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212

1313
<script lang="ts">
14+
// Globals
15+
import { IN_BROWSER } from '#v0/constants/globals'
16+
1417
// Components
1518
import { Atom } from '#v0/components/Atom'
1619
import SelectHiddenInput from './SelectHiddenInput.vue'
@@ -158,7 +161,7 @@
158161
const virtualFocus = useVirtualFocus(
159162
() => selection.values().map(ticket => ({
160163
id: ticket.id,
161-
el: () => document.querySelector<HTMLElement>(`#${CSS.escape(`${id}-option-${ticket.id}`)}`),
164+
el: () => IN_BROWSER ? document.querySelector<HTMLElement>(`#${CSS.escape(`${id}-option-${ticket.id}`)}`) : null,
162165
disabled: ticket.disabled,
163166
})),
164167
{

packages/0/src/composables/createCombobox/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
* ```
2828
*/
2929

30+
// Globals
31+
import { IN_BROWSER } from '#v0/constants/globals'
32+
3033
// Composables
3134
import { useContext } from '#v0/composables/createContext'
3235
import { createSelection } from '#v0/composables/createSelection'
@@ -194,7 +197,7 @@ export function createCombobox (options: ComboboxOptions = {}): ComboboxContext
194197
.filter(ticket => filtered.value.has(ticket.id) && !toValue(ticket.disabled))
195198
.map(ticket => ({
196199
id: ticket.id,
197-
el: () => document.querySelector<HTMLElement>(`#${CSS.escape(`${id}-option-${ticket.id}`)}`),
200+
el: () => IN_BROWSER ? document.querySelector<HTMLElement>(`#${CSS.escape(`${id}-option-${ticket.id}`)}`) : null,
198201
disabled: ticket.disabled,
199202
})),
200203
{

packages/0/src/composables/useClickOutside/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
* ```
3232
*/
3333

34+
// Globals
35+
import { IN_BROWSER } from '#v0/constants/globals'
36+
3437
// Composables
3538
import {
3639
useDocumentEventListener,
@@ -349,6 +352,7 @@ export function useClickOutside (
349352
* Handle window blur - detect focus moving to iframe.
350353
*/
351354
function onBlur (event: FocusEvent) {
355+
if (!IN_BROWSER) return
352356
if (isPaused.value) return
353357
if (event.defaultPrevented) return
354358

packages/0/src/composables/useHotkey/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export function useHotkey (
162162
let groupIndex = 0
163163

164164
function isInputFocused (): boolean {
165+
if (!IN_BROWSER) return false
165166
if (toValue(inputs)) return false
166167

167168
const activeElement = document.activeElement as HTMLElement | null

0 commit comments

Comments
 (0)