@@ -4,7 +4,7 @@ import type { RouteLocationNormalized, Router } from 'vue-router'
44import { clamp } from '@antfu/utils'
55import { parseRangeString } from '@slidev/parser/utils'
66import { createSharedComposable , injectLocal } from '@vueuse/core'
7- import { computed , ref , toRaw , watch } from 'vue'
7+ import { computed , hasInjectionContext , ref , toRaw , watch } from 'vue'
88import { useRoute , useRouter } from 'vue-router'
99import { slides } from '#slidev/slides'
1010import { CLICKS_MAX , injectionSlidevContext } from '../constants'
@@ -404,7 +404,13 @@ const useSharedNav = createSharedComposable((): SlidevContextNavFull => {
404404
405405export function useNav ( ) : SlidevContextNavFull {
406406 const nav = useSharedNav ( )
407- const context = injectLocal ( injectionSlidevContext , undefined )
407+ // `useNav()` is also called outside of `setup()`, most notably from the
408+ // `mounted`/`created` hooks of the `v-motion` and `v-mark` directives.
409+ // `injectLocal` throws there, and there is no slide-local context to read
410+ // anyway, so fall back to the shared nav.
411+ const context = hasInjectionContext ( )
412+ ? injectLocal ( injectionSlidevContext , undefined )
413+ : undefined
408414 if ( ! context )
409415 return nav
410416
0 commit comments