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

Commit 573c70e

Browse files
author
X
authored
Merge pull request #38 from alephjs/fix-head-script-ssr
fix: fix head scripts prints
2 parents 8c87b48 + dd09d00 commit 573c70e

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

head.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export default function Head(props: PropsWithChildren<{}>) {
3232
}
3333

3434
nodes.forEach(({ type, props }) => {
35+
if (type === 'script') {
36+
return
37+
}
3538
const el = doc.createElement(type)
3639
Object.keys(props).forEach(key => {
3740
const value = props[key]

renderer.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,21 @@ export async function renderPage(
132132
}
133133

134134
rendererCache.headElements.forEach(({ type, props }) => {
135+
const { children, ...rest } = props
135136
if (type === 'title') {
136-
if (util.isNEString(props.children)) {
137-
ret.head.push(`<title ssr>${props.children}</title>`)
138-
} else if (util.isNEArray(props.children)) {
139-
ret.head.push(`<title ssr>${props.children.join('')}</title>`)
137+
if (util.isNEString(children)) {
138+
ret.head.push(`<title ssr>${children}</title>`)
139+
} else if (util.isNEArray(children)) {
140+
ret.head.push(`<title ssr>${children.join('')}</title>`)
140141
}
141142
} else {
142-
const attrs = Object.keys(props)
143-
.filter(key => key !== 'children')
144-
.map(key => ` ${key}=${JSON.stringify(props[key])}`)
145-
.join('')
146-
if (util.isNEString(props.children)) {
147-
ret.head.push(`<${type}${attrs} ssr>${props.children}</${type}>`)
148-
} else if (util.isNEArray(props.children)) {
149-
ret.head.push(`<${type}${attrs} ssr>${props.children.join('')}</${type}>`)
143+
const attrs = Object.entries(rest).map(([key, value]) => ` ${key}=${JSON.stringify(value)}`).join('')
144+
if (type === 'script') {
145+
ret.head.push(`<${type}${attrs}>${Array.isArray(children) ? children.join('') : children || ''}</${type}>`)
146+
} else if (util.isNEString(children)) {
147+
ret.head.push(`<${type}${attrs} ssr>${children}</${type}>`)
148+
} else if (util.isNEArray(children)) {
149+
ret.head.push(`<${type}${attrs} ssr>${children.join('')}</${type}>`)
150150
} else {
151151
ret.head.push(`<${type}${attrs} ssr />`)
152152
}

0 commit comments

Comments
 (0)