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

Commit 730cc1f

Browse files
author
Je
committed
refactor: make moduleId startsWith '/'
1 parent 943b518 commit 730cc1f

File tree

4 files changed

+67
-72
lines changed

4 files changed

+67
-72
lines changed

app.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ export function ALEPH({ initial }: {
8181
setData(data)
8282
}
8383
const onAddModule = async ({ moduleId, hash }: Module) => {
84-
if (moduleId === './404.js') {
84+
if (moduleId === '/404.js') {
8585
const { default: Component } = await import(getModuleImportUrl(baseUrl, { moduleId, hash }) + '?t=' + Date.now())
8686
if (util.isLikelyReactComponent(Component)) {
8787
setE404({ Component })
8888
} else {
8989
setE404({ Component: E404Page })
9090
}
91-
} else if (moduleId === './app.js') {
91+
} else if (moduleId === '/app.js') {
9292
const { default: Component } = await import(getModuleImportUrl(baseUrl, { moduleId, hash }) + '?t=' + Date.now())
9393
if (util.isLikelyReactComponent(Component)) {
9494
setApp({ Component })
@@ -98,11 +98,11 @@ export function ALEPH({ initial }: {
9898
Component: E501App
9999
}))
100100
}
101-
} else if (moduleId === './data.js' || moduleId === './data/index.js') {
101+
} else if (moduleId === '/data.js' || moduleId === '/data/index.js') {
102102
const { default: data } = await import(getModuleImportUrl(baseUrl, { moduleId, hash }) + '?t=' + Date.now())
103103
console.log('[DATA]', data)
104104
setData(data)
105-
} else if (moduleId.startsWith('./pages/')) {
105+
} else if (moduleId.startsWith('/pages/')) {
106106
const pagePath = util.trimSuffix(moduleId, '.js').replace(/\s+/g, '-').replace(/\/?index$/i, '/')
107107
setPageModules(pageModules => ({
108108
...pageModules,
@@ -111,14 +111,14 @@ export function ALEPH({ initial }: {
111111
}
112112
}
113113
const onRemoveModule = (moduleId: string) => {
114-
if (moduleId === './404.js') {
114+
if (moduleId === '/404.js') {
115115
setE404({ Component: E404Page })
116-
} else if (moduleId === './app.js') {
116+
} else if (moduleId === '/app.js') {
117117
setApp({ Component: null })
118-
} else if (moduleId === './data.js' || moduleId === './data/index.js') {
118+
} else if (moduleId === '/data.js' || moduleId === '/data/index.js') {
119119
console.log('[DATA]', {})
120120
setData({})
121-
} else if (moduleId.startsWith('./pages/')) {
121+
} else if (moduleId.startsWith('/pages/')) {
122122
setPageModules(pageModules => {
123123
const newPageModules: Record<string, { moduleId: string, hash: string }> = {}
124124
for (const pagePath in pageModules) {

importor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export function StyleLoader({ path, rawPath, resolveDir }: LoaderProps) {
4040
useEffect(() => {
4141
import(util.cleanPath(`/_aleph/${resolveDir}/${path}`))
4242
return () => {
43-
const moduleId = util.cleanPath(`./${resolveDir}/${rawPath}`)
43+
const moduleId = util.cleanPath(`/${resolveDir}/${rawPath}`)
4444
const { document } = (window as any)
4545
Array.from(document.head.children).forEach((el: any) => {
4646
if (el.getAttribute('data-module-id') === moduleId) {

0 commit comments

Comments
 (0)