@@ -27,6 +27,12 @@ interface Module {
27
27
hash : string
28
28
}
29
29
30
+ interface Renderer {
31
+ renderPage : Function
32
+ renderHead : Function
33
+ E501Page : Function
34
+ }
35
+
30
36
interface RenderResult {
31
37
url : RouterURL
32
38
status : number
@@ -45,6 +51,7 @@ export class Project {
45
51
#routing: Routing = new Routing ( )
46
52
#apiRouting: Routing = new Routing ( )
47
53
#fsWatchListeners: Array < EventEmitter > = [ ]
54
+ #renderer: Renderer = { renderPage : ( ) => void 0 , renderHead : ( ) => void 0 , E501Page : ( ) => null }
48
55
49
56
constructor ( dir : string , mode : 'development' | 'production' ) {
50
57
this . mode = mode
@@ -376,9 +383,9 @@ export class Project {
376
383
377
384
const { deps, modules, styles } = moduleState
378
385
log . info ( colors . bold ( ' Modules' ) )
379
- log . info ( ' ▲ ' , colors . bold ( deps . count . toString ( ) ) , 'deps' , colors . dim ( `• ${ util . bytesString ( deps . bytes ) } (mini, uncompress)` ) )
380
- log . info ( ' ▲ ' , colors . bold ( modules . count . toString ( ) ) , 'modules' , colors . dim ( `• ${ util . bytesString ( modules . bytes ) } (mini, uncompress)` ) )
381
- log . info ( ' ▲ ' , colors . bold ( styles . count . toString ( ) ) , 'styles' , colors . dim ( `• ${ util . bytesString ( styles . bytes ) } (mini, uncompress)` ) )
386
+ log . info ( ' {} ' , colors . bold ( deps . count . toString ( ) ) , 'deps' , colors . dim ( `• ${ util . bytesString ( deps . bytes ) } (mini, uncompress)` ) )
387
+ log . info ( ' {} ' , colors . bold ( modules . count . toString ( ) ) , 'modules' , colors . dim ( `• ${ util . bytesString ( modules . bytes ) } (mini, uncompress)` ) )
388
+ log . info ( ' {} ' , colors . bold ( styles . count . toString ( ) ) , 'styles' , colors . dim ( `• ${ util . bytesString ( styles . bytes ) } (mini, uncompress)` ) )
382
389
383
390
log . info ( `Done in ${ Math . round ( performance . now ( ) - start ) } ms` )
384
391
}
@@ -530,6 +537,11 @@ export class Project {
530
537
}
531
538
await this . _createMainModule ( )
532
539
540
+ // ensure react in deno is same with browser one
541
+ const { renderPage, renderHead } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile )
542
+ const { E501Page } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/error.js' ) ! . jsFile )
543
+ this . #renderer = { renderPage, renderHead, E501Page }
544
+
533
545
log . info ( colors . bold ( 'Aleph.js' ) )
534
546
log . info ( colors . bold ( ' Config' ) )
535
547
if ( this . #modules. has ( '/data.js' ) ) {
@@ -1181,11 +1193,15 @@ export class Project {
1181
1193
try {
1182
1194
const appModule = this . #modules. get ( '/app.js' )
1183
1195
const e404Module = this . #modules. get ( '/404.js' )
1184
- const { E501Page } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/error.js' ) ! . jsFile )
1185
- const { renderPage, renderHead } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile )
1186
- const { default : App } = appModule && url . pagePath != '' ? await import ( 'file://' + appModule . jsFile ) : { } as any
1187
- const { default : E404 } = e404Module ? await import ( 'file://' + e404Module . jsFile ) : { } as any
1188
- const staticData = await this . getStaticData ( )
1196
+ const [
1197
+ { default : App } , // todo: cache, re-import when hash changed
1198
+ { default : E404 } , // todo: cache, re-import when hash changed
1199
+ staticData // todo: real static
1200
+ ] = await Promise . all ( [
1201
+ appModule && url . pagePath != '' ? await import ( 'file://' + appModule . jsFile ) : Promise . resolve ( { } ) ,
1202
+ e404Module ? await import ( 'file://' + e404Module . jsFile ) : Promise . resolve ( { } ) ,
1203
+ await this . getStaticData ( )
1204
+ ] )
1189
1205
const pageComponentTree : { id : string , Component ?: any } [ ] = pageModuleTree . map ( ( { id } ) => ( { id } ) )
1190
1206
const imports = pageModuleTree . map ( async ( { id } ) => {
1191
1207
const mod = this . #modules. get ( id ) !
@@ -1195,13 +1211,13 @@ export class Project {
1195
1211
if ( util . isLikelyReactComponent ( C ) ) {
1196
1212
pc . Component = C
1197
1213
} else {
1198
- pc . Component = E501Page
1214
+ pc . Component = this . #renderer . E501Page
1199
1215
}
1200
1216
}
1201
1217
} )
1202
1218
await Promise . all ( imports )
1203
- const html = renderPage ( url , staticData , App , E404 , pageComponentTree )
1204
- const head = await renderHead ( [
1219
+ const html = this . #renderer . renderPage ( url , staticData , App , E404 , pageComponentTree )
1220
+ const head = await this . #renderer . renderHead ( [
1205
1221
appModule ? this . _lookupStyleDeps ( appModule . id ) : [ ] ,
1206
1222
...pageModuleTree . map ( ( { id } ) => this . _lookupStyleDeps ( id ) )
1207
1223
] . flat ( ) )
0 commit comments