@@ -503,6 +503,21 @@ export class Project {
503
503
if ( validated ) {
504
504
const moduleID = path . replace ( reModuleExt , '.js' )
505
505
util . debounceX ( moduleID , ( ) => {
506
+ const shouldUpdateMainModule = ( ( ) => {
507
+ switch ( moduleID ) {
508
+ case '/404.js' :
509
+ case '/app.js' :
510
+ case '/data.js' : {
511
+ return true
512
+ }
513
+ default : {
514
+ if ( path . startsWith ( '/page/' ) ) {
515
+ return true
516
+ }
517
+ return false
518
+ }
519
+ }
520
+ } ) ( )
506
521
if ( existsFileSync ( p ) ) {
507
522
let type = 'modify'
508
523
if ( ! this . #modules. has ( moduleID ) ) {
@@ -520,10 +535,12 @@ export class Project {
520
535
}
521
536
if ( moduleID . startsWith ( '/pages/' ) ) {
522
537
this . #routing. update ( this . _getPageModule ( mod ) )
523
- this . _createMainModule ( )
524
538
} else if ( moduleID . startsWith ( '/api/' ) ) {
525
539
this . #apiRouting. update ( this . _getPageModule ( mod ) )
526
540
}
541
+ if ( shouldUpdateMainModule ) {
542
+ this . _createMainModule ( )
543
+ }
527
544
this . _updateDependency ( path , mod . hash , ( { id : moduleID } ) => {
528
545
if ( ! hmrable && this . isHMRable ( moduleID ) ) {
529
546
this . #fsWatchListeners. forEach ( e => e . emit ( 'modify-' + moduleID , mod . hash ) )
@@ -535,10 +552,12 @@ export class Project {
535
552
} else if ( this . #modules. has ( moduleID ) ) {
536
553
if ( moduleID . startsWith ( '/pages/' ) ) {
537
554
this . #routing. removeRoute ( moduleID )
538
- this . _createMainModule ( )
539
555
} else if ( moduleID . startsWith ( '/api/' ) ) {
540
556
this . #apiRouting. removeRoute ( moduleID )
541
557
}
558
+ if ( shouldUpdateMainModule ) {
559
+ this . _createMainModule ( )
560
+ }
542
561
this . #modules. delete ( moduleID )
543
562
if ( this . isHMRable ( moduleID ) ) {
544
563
this . #fsWatchListeners. forEach ( e => e . emit ( 'remove' , moduleID ) )
@@ -1057,9 +1076,11 @@ export class Project {
1057
1076
} )
1058
1077
try {
1059
1078
const appModule = this . #modules. get ( '/app.js' )
1079
+ const e404Module = this . #modules. get ( '/404.js' )
1060
1080
const { E501Page } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/error.js' ) ! . jsFile )
1061
1081
const { renderPage, renderHead } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile )
1062
1082
const { default : App } = appModule && url . pagePath != '' ? await import ( 'file://' + appModule . jsFile ) : { } as any
1083
+ const { default : E404 } = e404Module ? await import ( 'file://' + e404Module . jsFile ) : { } as any
1063
1084
const staticData = await this . getStaticData ( )
1064
1085
const pageComponentTree : { id : string , Component ?: any } [ ] = pageModuleTree . map ( ( { id } ) => ( { id } ) )
1065
1086
const imports = pageModuleTree . map ( async ( { id } ) => {
@@ -1075,7 +1096,7 @@ export class Project {
1075
1096
}
1076
1097
} )
1077
1098
await Promise . all ( imports )
1078
- const html = renderPage ( url , staticData , App , pageComponentTree )
1099
+ const html = renderPage ( url , staticData , App , E404 , pageComponentTree )
1079
1100
const head = await renderHead ( [
1080
1101
appModule ? this . _lookupStyleDeps ( appModule . id ) : [ ] ,
1081
1102
...pageModuleTree . map ( ( { id } ) => this . _lookupStyleDeps ( id ) )
0 commit comments