Skip to content

Commit 1e40ca8

Browse files
committed
fix: injection_return undefined, close #138
1 parent c796152 commit 1e40ca8

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

packages/client/modules/directives.ts

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ export default function createDirectives() {
3131

3232
const prev = elements?.value?.length || 0
3333

34-
if (!elements?.value?.includes(el))
34+
if (elements && !elements?.value?.includes(el))
3535
elements.value.push(el)
3636

3737
el?.classList.toggle(CLASS_VCLICK_TARGET, true)
3838

39-
watch(
40-
clicks,
41-
() => {
42-
const c = clicks?.value ?? 0
43-
const show = dir.value != null
44-
? c >= dir.value
45-
: c > prev
46-
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
47-
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
48-
},
49-
{ immediate: true },
50-
)
39+
if (clicks) {
40+
watch(
41+
clicks,
42+
() => {
43+
const c = clicks?.value ?? 0
44+
const show = dir.value != null
45+
? c >= dir.value
46+
: c > prev
47+
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
48+
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
49+
},
50+
{ immediate: true },
51+
)
52+
}
5153
},
5254
unmounted(el: HTMLElement, dir) {
5355
el?.classList.toggle(CLASS_VCLICK_TARGET, false)
@@ -72,15 +74,17 @@ export default function createDirectives() {
7274

7375
el?.classList.toggle(CLASS_VCLICK_TARGET, true)
7476

75-
watch(
76-
clicks,
77-
() => {
78-
const show = (clicks.value ?? 0) >= (dir.value ?? prev ?? 0)
79-
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
80-
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
81-
},
82-
{ immediate: true },
83-
)
77+
if (clicks) {
78+
watch(
79+
clicks,
80+
() => {
81+
const show = (clicks.value ?? 0) >= (dir.value ?? prev ?? 0)
82+
if (!el.classList.contains(CLASS_VCLICK_HIDDEN_EXP))
83+
el.classList.toggle(CLASS_VCLICK_HIDDEN, !show)
84+
},
85+
{ immediate: true },
86+
)
87+
}
8488
},
8589
unmounted(el: HTMLElement) {
8690
el?.classList.toggle(CLASS_VCLICK_TARGET, true)
@@ -99,15 +103,17 @@ export default function createDirectives() {
99103

100104
el?.classList.toggle(CLASS_VCLICK_TARGET, true)
101105

102-
watch(
103-
clicks,
104-
() => {
105-
const hide = (clicks?.value || 0) > dir.value
106-
el.classList.toggle(CLASS_VCLICK_HIDDEN, hide)
107-
el.classList.toggle(CLASS_VCLICK_HIDDEN_EXP, hide)
108-
},
109-
{ immediate: true },
110-
)
106+
if (clicks) {
107+
watch(
108+
clicks,
109+
() => {
110+
const hide = (clicks?.value || 0) > dir.value
111+
el.classList.toggle(CLASS_VCLICK_HIDDEN, hide)
112+
el.classList.toggle(CLASS_VCLICK_HIDDEN_EXP, hide)
113+
},
114+
{ immediate: true },
115+
)
116+
}
111117
},
112118
unmounted(el, dir) {
113119
el?.classList.toggle(CLASS_VCLICK_TARGET, false)

packages/client/setup/root.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function setupRoot() {
2929
if (+serverState.value.page !== +currentPage.value || clicks.value !== serverState.value.clicks) {
3030
router.replace({
3131
path: getPath(serverState.value.page),
32-
query: { ...router.currentRoute.query, clicks: serverState.value.clicks || 0 },
32+
query: { ...router.currentRoute.value.query, clicks: serverState.value.clicks || 0 },
3333
})
3434
}
3535
},

packages/slidev/node/plugins/setupClient.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ export function createClientSetupPlugin({ clientRoot, themeRoots, userRoot }: Re
3030
imports.push(`import __n${idx} from '${toAtFS(path)}'`)
3131
injections.push(
3232
`// ${path}`,
33-
`injection_return = __n${idx}()`,
33+
(code.includes('injection_return'))
34+
? `injection_return = __n${idx}();`
35+
: `__n${idx}();`,
3436
)
3537
asyncInjections.push(
3638
`// ${path}`,
37-
`await __n${idx}(injection_arg)`,
39+
`await __n${idx}(injection_arg);`,
3840
)
3941
})
4042

0 commit comments

Comments
 (0)