Skip to content

Commit

Permalink
fix: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
c0dedance committed Oct 30, 2023
1 parent 076cba0 commit 2a2f5fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function renderPage({
const renderIndexHTML = (
appHtml: string,
islandsCode: string,
propsData: unknown[]
islandProps: unknown[]
) =>
`\
<!DOCTYPE html>
Expand All @@ -67,21 +67,25 @@ export async function renderPage({
<div id="root">${appHtml}</div>
<script type="module">${islandsCode}</script>
<script type="module" src="/${clientChunk?.fileName}"></script>
<script id="island-props">${JSON.stringify(propsData)}</script>
<script id="island-props">${JSON.stringify(islandProps)}</script>
</body>
</html>`.trim()
console.log(`Rendering page in server side...`)
await Promise.all(
routes.map(async (r) => {
// 渲染路由对应的页面
const { appHtml, islandPathToMap, propsData = [] } = await render(r.path)
const {
appHtml,
islandPathToMap,
islandProps = [],
} = await render(r.path)

// 打包 Islands 组件代码
const islandBundle = await buildIslands(root, islandPathToMap)
const islandsCode = (islandBundle as RollupOutput).output[0].code

// 组件HTML嵌入到模板中
const html = renderIndexHTML(appHtml, islandsCode, propsData)
const html = renderIndexHTML(appHtml, islandsCode, islandProps)
// htlm文件名处理
const outputFilePath = r.path.endsWith('/')
? `${r.path}index.html`
Expand Down
5 changes: 3 additions & 2 deletions src/runtime/ssr-entry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DataContext } from './hooks'

export interface RenderResult {
appHtml: string
propsData: unknown[]
islandProps: unknown[]
islandPathToMap: Record<string, string>
}

Expand All @@ -15,7 +15,6 @@ export async function render(pagePath: string) {
const pageData = await initPageData(pagePath)
// 清除 islands 数据
const { clearIslandData, data } = await import('./jsx-runtime')
const { islandProps, islandPathToMap } = data
clearIslandData()

const appHtml = renderToString(
Expand All @@ -25,6 +24,8 @@ export async function render(pagePath: string) {
</StaticRouter>
</DataContext.Provider>
)
// 保证每次都能拿到最新的数据
const { islandProps, islandPathToMap } = data
return {
appHtml,
islandProps,
Expand Down

0 comments on commit 2a2f5fb

Please sign in to comment.