Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit eb6c8b1

Browse files
author
Je
committed
fix: fix custom 404 page render
1 parent 5b54e8e commit eb6c8b1

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

error.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function ErrorPage({ status, text = getStatusText(status), refreshButton
6666
React.createElement(
6767
'title',
6868
null,
69-
status + ' - ' + text
69+
`${status} - ${text} | Aleph.js`
7070
),
7171
),
7272
React.createElement(

project.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,21 @@ export class Project {
503503
if (validated) {
504504
const moduleID = path.replace(reModuleExt, '.js')
505505
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+
})()
506521
if (existsFileSync(p)) {
507522
let type = 'modify'
508523
if (!this.#modules.has(moduleID)) {
@@ -520,10 +535,12 @@ export class Project {
520535
}
521536
if (moduleID.startsWith('/pages/')) {
522537
this.#routing.update(this._getPageModule(mod))
523-
this._createMainModule()
524538
} else if (moduleID.startsWith('/api/')) {
525539
this.#apiRouting.update(this._getPageModule(mod))
526540
}
541+
if (shouldUpdateMainModule) {
542+
this._createMainModule()
543+
}
527544
this._updateDependency(path, mod.hash, ({ id: moduleID }) => {
528545
if (!hmrable && this.isHMRable(moduleID)) {
529546
this.#fsWatchListeners.forEach(e => e.emit('modify-' + moduleID, mod.hash))
@@ -535,10 +552,12 @@ export class Project {
535552
} else if (this.#modules.has(moduleID)) {
536553
if (moduleID.startsWith('/pages/')) {
537554
this.#routing.removeRoute(moduleID)
538-
this._createMainModule()
539555
} else if (moduleID.startsWith('/api/')) {
540556
this.#apiRouting.removeRoute(moduleID)
541557
}
558+
if (shouldUpdateMainModule) {
559+
this._createMainModule()
560+
}
542561
this.#modules.delete(moduleID)
543562
if (this.isHMRable(moduleID)) {
544563
this.#fsWatchListeners.forEach(e => e.emit('remove', moduleID))
@@ -1057,9 +1076,11 @@ export class Project {
10571076
})
10581077
try {
10591078
const appModule = this.#modules.get('/app.js')
1079+
const e404Module = this.#modules.get('/404.js')
10601080
const { E501Page } = await import('file://' + this.#modules.get('//deno.land/x/aleph/error.js')!.jsFile)
10611081
const { renderPage, renderHead } = await import('file://' + this.#modules.get('//deno.land/x/aleph/renderer.js')!.jsFile)
10621082
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
10631084
const staticData = await this.getStaticData()
10641085
const pageComponentTree: { id: string, Component?: any }[] = pageModuleTree.map(({ id }) => ({ id }))
10651086
const imports = pageModuleTree.map(async ({ id }) => {
@@ -1075,7 +1096,7 @@ export class Project {
10751096
}
10761097
})
10771098
await Promise.all(imports)
1078-
const html = renderPage(url, staticData, App, pageComponentTree)
1099+
const html = renderPage(url, staticData, App, E404, pageComponentTree)
10791100
const head = await renderHead([
10801101
appModule ? this._lookupStyleDeps(appModule.id) : [],
10811102
...pageModuleTree.map(({ id }) => this._lookupStyleDeps(id))

renderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ export function renderPage(
1111
url: RouterURL,
1212
staticData: Record<string, any>,
1313
App: ComponentType<PageProps> | undefined,
14+
E404: ComponentType | undefined,
1415
pageComponentTree: { id: string, Component?: any }[]
1516
) {
1617
const pageProps: PageProps = {
17-
Page: pageComponentTree.length > 0 ? pageComponentTree[0].Component || (() => null) : E404Page,
18+
Page: pageComponentTree.length > 0 ? pageComponentTree[0].Component || (() => null) : E404 || E404Page,
1819
pageProps: {}
1920
}
2021
if (pageComponentTree.length > 1) {

0 commit comments

Comments
 (0)