@@ -316,30 +316,27 @@ export class Application implements ServerApplication {
316
316
}
317
317
if ( hmrable ) {
318
318
let routePath : string | undefined = undefined
319
- let useDeno : boolean | undefined = undefined
319
+ let withData : boolean | undefined = undefined
320
320
let isIndex : boolean | undefined = undefined
321
321
if ( module . url . startsWith ( '/pages/' ) ) {
322
322
const [ path , _ , options ] = this . createRouteUpdate ( module . url )
323
323
routePath = path
324
- useDeno = options . useDeno
324
+ withData = options . withData
325
325
isIndex = options . isIndex
326
326
} else {
327
327
if ( [ '/app' , '/404' ] . includes ( trimModuleExt ( module . url ) ) ) {
328
- this . lookupDeps ( module . url , dep => {
329
- if ( this . getModule ( dep . url ) ?. useDenoHook ) {
330
- useDeno = true
331
- return false
332
- }
333
- } )
328
+ if ( this . hasSSRData ( module . url ) ) {
329
+ withData = true
330
+ }
334
331
}
335
332
}
336
333
if ( type === 'add' ) {
337
334
this . #fsWatchListeners. forEach ( e => {
338
- e . emit ( 'add' , { url : module . url , routePath, isIndex, useDeno } )
335
+ e . emit ( 'add' , { url : module . url , routePath, isIndex, withData } )
339
336
} )
340
337
} else {
341
338
this . #fsWatchListeners. forEach ( e => {
342
- e . emit ( 'modify-' + module . url , { useDeno } )
339
+ e . emit ( 'modify-' + module . url , { withData } )
343
340
} )
344
341
}
345
342
}
@@ -603,16 +600,13 @@ export class Application implements ServerApplication {
603
600
sharedModules : Array . from ( this . #modules. values ( ) ) . filter ( ( { url } ) => {
604
601
return [ '/app' , '/404' ] . includes ( trimModuleExt ( url ) )
605
602
} ) . map ( ( { url } ) => {
606
- let useDeno : boolean | undefined = undefined
603
+ let withData : boolean | undefined = undefined
607
604
if ( this . config . ssr !== false ) {
608
- this . lookupDeps ( url , dep => {
609
- if ( this . getModule ( dep . url ) ?. useDenoHook ) {
610
- useDeno = true
611
- return false
612
- }
613
- } )
605
+ if ( this . hasSSRData ( url ) ) {
606
+ withData = true
607
+ }
614
608
}
615
- return { url, useDeno }
609
+ return { url, withData }
616
610
} ) ,
617
611
renderMode : this . config . ssr ? 'ssr' : 'spa'
618
612
}
@@ -786,19 +780,16 @@ export class Application implements ServerApplication {
786
780
log . info ( `Done in ${ Math . round ( performance . now ( ) - start ) } ms` )
787
781
}
788
782
789
- private createRouteUpdate ( url : string ) : [ string , string , { isIndex ?: boolean , useDeno ?: boolean } ] {
783
+ private createRouteUpdate ( url : string ) : [ string , string , { isIndex ?: boolean , withData ?: boolean } ] {
790
784
const isBuiltinModule = moduleExts . some ( ext => url . endsWith ( '.' + ext ) )
791
785
let routePath = isBuiltinModule ? toPagePath ( url ) : util . trimSuffix ( url , '/pages' )
792
- let useDeno : boolean | undefined = undefined
786
+ let withData : boolean | undefined = undefined
793
787
let isIndex : boolean | undefined = undefined
794
788
795
- if ( this . config . ssr !== false ) {
796
- this . lookupDeps ( url , dep => {
797
- if ( this . getModule ( dep . url ) ?. useDenoHook ) {
798
- useDeno = true
799
- return false
800
- }
801
- } )
789
+ if ( this . config . ssr !== false && ! url . startsWith ( '/api/' ) ) {
790
+ if ( this . hasSSRData ( url ) ) {
791
+ withData = true
792
+ }
802
793
}
803
794
804
795
if ( ! isBuiltinModule ) {
@@ -823,7 +814,7 @@ export class Application implements ServerApplication {
823
814
}
824
815
}
825
816
826
- return [ routePath , url , { isIndex, useDeno } ]
817
+ return [ routePath , url , { isIndex, withData } ]
827
818
}
828
819
829
820
/** fetch resource by the url. */
@@ -1403,6 +1394,21 @@ export class Application implements ServerApplication {
1403
1394
return ssr
1404
1395
}
1405
1396
1397
+ private hasSSRData ( url : string ) {
1398
+ let hasData = false
1399
+ if ( this . getModule ( url ) ?. useDenoHook ) {
1400
+ hasData = true
1401
+ } else {
1402
+ this . lookupDeps ( url , dep => {
1403
+ if ( this . getModule ( dep . url ) ?. useDenoHook ) {
1404
+ hasData = true
1405
+ return false
1406
+ }
1407
+ } )
1408
+ }
1409
+ return hasData
1410
+ }
1411
+
1406
1412
/** lookup app deps recurively. */
1407
1413
lookupDeps (
1408
1414
url : string ,
0 commit comments