Skip to content

Commit 89bc719

Browse files
committed
fix: fallback to useId for vapor
1 parent 607f25d commit 89bc719

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎packages/router/src/experimental/scroll-restoration.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
onDeactivated,
1313
onScopeDispose,
1414
toValue,
15+
useId,
1516
} from 'vue'
1617
import { diagnostics } from '../diagnostics'
1718
import { START_LOCATION_NORMALIZED } from '../location'
@@ -300,7 +301,8 @@ const SCROLL_RESTORATION_REGISTRATIONS: InjectionKey<
300301
[
301302
registrations: Map<
302303
ScrollRestorationRegistration,
303-
ComponentInternalInstance
304+
// vapor doesn't support getCurrentInstance()
305+
ComponentInternalInstance | string
304306
>,
305307
restore: (
306308
registration: ScrollRestorationRegistration,
@@ -502,9 +504,11 @@ function useScrollRestorationClient<
502504
const [registrations, restore, isActive] = inject(
503505
SCROLL_RESTORATION_REGISTRATIONS
504506
)!
505-
const globalOptions = inject(SCROLL_RESTORATION_OPTIONS_KEY)!
506-
const optionsWithDefaults = { ...globalOptions, ...options }
507-
const instance = getCurrentInstance()!
507+
const optionsWithDefaults = {
508+
...inject(SCROLL_RESTORATION_OPTIONS_KEY)!,
509+
...options,
510+
}
511+
const instance = getCurrentInstance() || useId()
508512

509513
const add = () => registrations.set(optionsWithDefaults, instance)
510514
const remove = () => registrations.delete(optionsWithDefaults)

0 commit comments

Comments
 (0)