Skip to content

Commit 6bf284c

Browse files
authored
fix: slide note sync (#1157) (#1287)
1 parent 1fe6120 commit 6bf284c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

packages/client/logic/note.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export function useSlideInfo(id: number | undefined): UseSlideInfo {
4040
if (payload.id === id)
4141
info.value = payload.data
4242
})
43+
import.meta.hot?.on('slidev-update-note', (payload) => {
44+
if (payload.id === id && info.value.note.trim() !== payload.note.trim())
45+
info.value = { ...info.value, ...payload }
46+
})
4347
}
4448

4549
return {

packages/slidev/node/plugins/loaders.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ export function createSlidesLoader(
115115
if (type === 'json' && req.method === 'POST') {
116116
const body = await getBodyJson(req)
117117
const slide = data.slides[idx]
118-
hmrPages.add(idx)
118+
119+
const onlyNoteChanged = Object.keys(body).length === 2
120+
&& 'note' in body && body.raw === null
121+
if (!onlyNoteChanged)
122+
hmrPages.add(idx)
119123

120124
if (slide.source) {
121125
Object.assign(slide.source, body)
@@ -173,7 +177,6 @@ export function createSlidesLoader(
173177
if (
174178
a?.content.trim() === b?.content.trim()
175179
&& a?.title?.trim() === b?.title?.trim()
176-
&& a?.note === b?.note
177180
&& equal(a.frontmatter, b.frontmatter)
178181
&& Object.entries(a.snippetsUsed ?? {}).every(([file, oldContent]) => {
179182
try {
@@ -184,8 +187,20 @@ export function createSlidesLoader(
184187
return false
185188
}
186189
})
187-
)
190+
) {
191+
if (a?.note !== b?.note) {
192+
ctx.server.ws.send({
193+
type: 'custom',
194+
event: 'slidev-update-note',
195+
data: {
196+
id: i,
197+
note: b!.note || '',
198+
noteHTML: md.render(b!.note || ''),
199+
},
200+
})
201+
}
188202
continue
203+
}
189204

190205
ctx.server.ws.send({
191206
type: 'custom',

0 commit comments

Comments
 (0)