Skip to content

Commit 6ae7695

Browse files
authored
Merge pull request #63 from dennev/main
Refactor `renderTags` to use `flattenChildren` for processing nested children
2 parents a2930ae + 3028873 commit 6ae7695

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

.changeset/fancy-pugs-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/meta": patch
3+
---
4+
5+
Refactor `renderTags` to use `flattenChildren` for processing nested children.

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)