Skip to content

Commit 3cbd12c

Browse files
committed
fix: Refactor renderTags to use flattenChildren for processing nested children.
1 parent a2930ae commit 3cbd12c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
sharedConfig,
1010
useContext
1111
} from "solid-js";
12-
import { isServer, spread, escape, useAssets, ssr } from "solid-js/web";
12+
import { escape, isServer, spread, ssr, useAssets } from "solid-js/web";
1313

1414
export const MetaContext = createContext<MetaContextType>();
1515

@@ -232,6 +232,13 @@ export function useHead(tagDesc: TagDescription) {
232232
}
233233

234234
function renderTags(tags: Array<TagDescription>) {
235+
function flattenChildren(children: unknown): unknown | string {
236+
if (Array.isArray(children)) {
237+
return children.map(child => flattenChildren(child)).join("");
238+
}
239+
return children;
240+
}
241+
235242
return tags
236243
.map(tag => {
237244
const keys = Object.keys(tag.props);
@@ -246,13 +253,8 @@ function renderTags(tags: Array<TagDescription>) {
246253
)
247254
.join("");
248255

249-
let children = tag.props.children;
256+
const children = flattenChildren(tag.props.children);
250257

251-
if (Array.isArray(children)) {
252-
// in JavaScript, strings are concatenated with comma which is not what we want
253-
// we should join them manually instead
254-
children = children.join("");
255-
}
256258
if (tag.setting?.close) {
257259
return `<${tag.tag} data-sm="${tag.id}"${props}>${
258260
// @ts-expect-error

0 commit comments

Comments
 (0)