Skip to content

Commit 5b1a560

Browse files
fix(Listbox): skip highlightSelected side effects during SSR (#2607)
1 parent 2c6d918 commit 5b1a560

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

packages/core/src/Listbox/ListboxRoot.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export type ListboxRootEmits<T = AcceptableValue> = {
7979
import type { EventHook } from '@vueuse/core'
8080
import type { Ref } from 'vue'
8181
import { createEventHook, useVModel } from '@vueuse/core'
82+
import { isClient } from '@vueuse/shared'
8283
import { nextTick, ref, toRefs, watch } from 'vue'
8384
import { useCollection } from '@/Collection'
8485
import { VisuallyHiddenInput } from '@/VisuallyHidden'
@@ -324,6 +325,12 @@ function handleMultipleReplace(event: KeyboardEvent, targetEl: HTMLElement) {
324325
}
325326
326327
async function highlightSelected(event?: Event) {
328+
// highlightSelected is called inside a watch with immediate set to true.
329+
// This results in code execution during SSR.
330+
// Ensure this code only runs in a browser environment, since it performs
331+
// DOM-only side effects (focus, scrollIntoView, synthetic KeyboardEvent).
332+
if (!isClient)
333+
return
327334
await nextTick()
328335
if (isVirtual.value) {
329336
// Trigger on nextTick for Virtualizer to be mounted

0 commit comments

Comments
 (0)