@@ -75,6 +75,9 @@ export function createSlidesLoader(
75
75
76
76
const entryId = slash ( entry )
77
77
78
+ let _layouts_cache_time = 0
79
+ let _layouts_cache : Record < string , string > = { }
80
+
78
81
return [
79
82
{
80
83
name : 'slidev:loader' ,
@@ -140,7 +143,7 @@ export function createSlidesLoader(
140
143
const a = data . slides [ i ]
141
144
const b = newData . slides [ i ]
142
145
143
- if ( a ?. content . trim ( ) === b ?. content . trim ( ) && JSON . stringify ( a . frontmatter ) === JSON . stringify ( b . frontmatter ) )
146
+ if ( a ?. content . trim ( ) === b ?. content . trim ( ) && equal ( a . frontmatter , b . frontmatter ) )
144
147
continue
145
148
146
149
ctx . server . ws . send ( {
@@ -160,14 +163,16 @@ export function createSlidesLoader(
160
163
const vueModules = (
161
164
await Promise . all ( Array . from ( hmrPages ) . map ( async ( i ) => {
162
165
const file = `${ slidePrefix } ${ i + 1 } .md`
163
- return await VuePlugin . handleHotUpdate ! ( {
164
- ...ctx ,
165
- modules : Array . from ( ctx . server . moduleGraph . getModulesByFile ( file ) || [ ] ) ,
166
- file,
167
- async read ( ) {
168
- return await transformMarkdown ( ( < any > MarkdownPlugin . transform ) ( newData . slides [ i ] ?. content , file ) , i , newData )
169
- } ,
170
- } )
166
+ try {
167
+ const md = await transformMarkdown ( ( < any > MarkdownPlugin . transform ) ( newData . slides [ i ] ?. content , file ) , i , newData )
168
+ return await VuePlugin . handleHotUpdate ! ( {
169
+ ...ctx ,
170
+ modules : Array . from ( ctx . server . moduleGraph . getModulesByFile ( file ) || [ ] ) ,
171
+ file,
172
+ read ( ) { return md } ,
173
+ } )
174
+ }
175
+ catch { }
171
176
} ) ,
172
177
)
173
178
) . flatMap ( i => i || [ ] )
@@ -202,7 +207,7 @@ export function createSlidesLoader(
202
207
if ( id === '/@slidev/styles' )
203
208
return generateUserStyles ( )
204
209
205
- // styles
210
+ // monaco-types
206
211
if ( id === '/@slidev/monaco-types' )
207
212
return generateMonacoTypes ( )
208
213
@@ -265,6 +270,10 @@ export function createSlidesLoader(
265
270
}
266
271
267
272
async function getLayouts ( ) {
273
+ const now = Date . now ( )
274
+ if ( now - _layouts_cache_time < 2000 )
275
+ return _layouts_cache
276
+
268
277
const layouts : Record < string , string > = { }
269
278
270
279
const roots = [
@@ -287,6 +296,9 @@ export function createSlidesLoader(
287
296
}
288
297
}
289
298
299
+ _layouts_cache_time = now
300
+ _layouts_cache = layouts
301
+
290
302
return layouts
291
303
}
292
304
0 commit comments