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

Commit 616551d

Browse files
author
Je
committed
breaking: remove AppManifest
1 parent 2435339 commit 616551d

File tree

4 files changed

+48
-56
lines changed

4 files changed

+48
-56
lines changed

app.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import React, { ComponentType, useCallback, useEffect, useState } from 'https://esm.sh/react'
2-
import { AppManifestContext, DataContext, RouterContext } from './context.ts'
3-
import { E404Page, E501App, E501Page } from './error.ts'
2+
import { DataContext, RouterContext } from './context.ts'
3+
import { E404Page, E501App, E501Page, ErrorBoundary } from './error.ts'
44
import events from './events.ts'
55
import { createRouter } from './router.ts'
6-
import type { AppManifest, Module, RouterURL } from './types.ts'
6+
import type { Module, RouterURL } from './types.ts'
77
import util, { hashShort, reModuleExt } from './util.ts'
88

99
export function ALEPH({ initial }: {
1010
initial: {
11-
manifest: AppManifest
11+
baseUrl: string
12+
defaultLocale: string
13+
locales: string[]
1214
routing: Record<string, Module>
1315
url: RouterURL
1416
staticData: Record<string, any>
1517
components: Record<string, ComponentType<any>>
1618
}
1719
}) {
18-
const [manifest, setManifest] = useState(() => initial.manifest)
1920
const [staticData, setStaticData] = useState(() => initial.staticData)
2021
const [routing, setRouting] = useState(() => initial.routing)
22+
const [locales, setLocales] = useState(() => initial.locales)
2123
const [e404, setE404] = useState(() => {
2224
const { E404 } = initial.components
2325
return {
@@ -39,13 +41,13 @@ export function ALEPH({ initial }: {
3941
}
4042
})
4143
const onpopstate = useCallback(async () => {
42-
const { baseUrl, defaultLocale, locales } = manifest
44+
const { baseUrl, defaultLocale } = initial
4345
const url = createRouter(
4446
baseUrl,
4547
Object.keys(routing),
4648
{
4749
defaultLocale,
48-
locales: Object.keys(locales)
50+
locales
4951
}
5052
)
5153
if (url.pagePath && url.pagePath in routing) {
@@ -65,7 +67,7 @@ export function ALEPH({ initial }: {
6567
} else {
6668
setPage({ url, Component: null })
6769
}
68-
}, [manifest, routing])
70+
}, [routing, locales])
6971

7072
useEffect(() => {
7173
window.addEventListener('popstate', onpopstate)
@@ -78,7 +80,7 @@ export function ALEPH({ initial }: {
7880
}, [onpopstate])
7981

8082
useEffect(() => {
81-
const { baseUrl } = manifest
83+
const { baseUrl } = initial
8284
const onUpdateData = (data: any) => {
8385
console.log('[DATA]', data)
8486
setStaticData(data)
@@ -101,7 +103,7 @@ export function ALEPH({ initial }: {
101103
Component: E501App
102104
}))
103105
}
104-
} else if (mod.id === '/data.js' || mod.id === '/data/index.js') {
106+
} else if (mod.id === '/data.js') {
105107
const { default: data } = await import(getModuleImportUrl(baseUrl, mod) + '?t=' + Date.now())
106108
console.log('[DATA]', data)
107109
setStaticData(data)
@@ -118,7 +120,7 @@ export function ALEPH({ initial }: {
118120
setE404({ Component: E404Page })
119121
} else if (moduleId === '/app.js') {
120122
setApp({ Component: null })
121-
} else if (moduleId === '/data.js' || moduleId === '/data/index.js') {
123+
} else if (moduleId === '/data.js') {
122124
console.log('[DATA]', {})
123125
setStaticData({})
124126
} else if (moduleId.startsWith('/pages/')) {
@@ -144,20 +146,24 @@ export function ALEPH({ initial }: {
144146
events.off('add-module', onAddModule)
145147
events.off('remove-module', onRemoveModule)
146148
}
147-
}, [manifest])
149+
}, [])
148150

149-
return React.createElement(
150-
AppManifestContext.Provider,
151-
{ value: manifest },
151+
return (
152152
React.createElement(
153-
DataContext.Provider,
154-
{ value: staticData },
153+
ErrorBoundary,
154+
null,
155155
React.createElement(
156-
RouterContext.Provider,
157-
{ value: page.url },
158-
(page.Component && app.Component) && React.createElement(app.Component, { Page: page.Component }),
159-
(page.Component && !app.Component) && React.createElement(page.Component),
160-
!page.Component && React.createElement(e404.Component),
156+
DataContext.Provider,
157+
{ value: staticData },
158+
React.createElement(
159+
RouterContext.Provider,
160+
{ value: page.url },
161+
...[
162+
(page.Component && app.Component) && React.createElement(app.Component, { Page: page.Component }),
163+
(page.Component && !app.Component) && React.createElement(page.Component),
164+
!page.Component && React.createElement(e404.Component)
165+
].filter(Boolean),
166+
)
161167
)
162168
)
163169
)

bootstrap.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'https://esm.sh/react'
22
import { hydrate, render } from 'https://esm.sh/react-dom'
33
import { ALEPH, getModuleImportUrl } from './app.ts'
4-
import { ErrorBoundary } from './error.ts'
54
import { createRouter } from './router.ts'
6-
import type { AppManifest, Module, RouterURL } from './types.ts'
5+
import type { Module, RouterURL } from './types.ts'
76
import util, { hashShort, reModuleExt } from './util.ts'
87

98
export default async function bootstrap({
@@ -14,7 +13,10 @@ export default async function bootstrap({
1413
customAppModule,
1514
custom404Module,
1615
routing
17-
}: AppManifest & {
16+
}: {
17+
baseUrl: string
18+
defaultLocale: string
19+
locales: string[]
1820
staticDataModule?: Module
1921
customAppModule?: Module
2022
custom404Module?: Module
@@ -57,26 +59,24 @@ export default async function bootstrap({
5759
staticDataModule ? import(getModuleImportUrl(baseUrl, staticDataModule)) : Promise.resolve({ default: {} }),
5860
customAppModule ? import(getModuleImportUrl(baseUrl, customAppModule)) : Promise.resolve({}),
5961
custom404Module ? import(getModuleImportUrl(baseUrl, custom404Module)) : Promise.resolve({}),
60-
pageModule ? import(getModuleImportUrl(baseUrl, pageModule)) : Promise.resolve({}),
62+
import(getModuleImportUrl(baseUrl, pageModule))
6163
])
6264
const el = React.createElement(
63-
ErrorBoundary,
64-
null,
65-
React.createElement(
66-
ALEPH,
67-
{
68-
initial: {
69-
manifest: { baseUrl, defaultLocale, locales },
70-
routing,
71-
url,
72-
staticData,
73-
components: { E404, App, Page }
74-
}
65+
ALEPH,
66+
{
67+
initial: {
68+
baseUrl,
69+
defaultLocale,
70+
locales,
71+
routing,
72+
url,
73+
staticData,
74+
components: { E404, App, Page }
7575
}
76-
)
76+
}
7777
)
7878

79-
// import async sytle dependencies
79+
// import async style dependencies
8080
const asyncDeps: { url: string, hash: string }[] = []
8181
customAppModule?.asyncDeps?.forEach(deps => asyncDeps.push(deps))
8282
custom404Module?.asyncDeps?.forEach(deps => asyncDeps.push(deps))

context.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
import { createContext } from 'https://esm.sh/react'
2-
import type { AppManifest, RouterURL } from './types.ts'
3-
4-
export const AppManifestContext = createNamedContext<AppManifest>(
5-
'AppManifestContext',
6-
{
7-
baseUrl: '/',
8-
defaultLocale: 'en',
9-
locales: {},
10-
}
11-
)
2+
import type { RouterURL } from './types.ts'
123

134
export const DataContext = createNamedContext<Record<string, any>>(
145
'DataContext',

types.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface Config {
99
readonly importMap: {
1010
imports: Record<string, string>
1111
}
12+
readonly env: Record<string, string>
1213
}
1314

1415
export interface SSROptions {
@@ -17,12 +18,6 @@ export interface SSROptions {
1718
readonly exclude?: string[]
1819
}
1920

20-
export interface AppManifest {
21-
readonly baseUrl: string
22-
readonly defaultLocale: string
23-
readonly locales: Record<string, Record<string, string>>
24-
}
25-
2621
export interface RouterURL {
2722
readonly locale: string
2823
readonly pathname: string

0 commit comments

Comments
 (0)