diff --git a/.changeset/shiny-pots-render.md b/.changeset/shiny-pots-render.md new file mode 100644 index 0000000..c2002c8 --- /dev/null +++ b/.changeset/shiny-pots-render.md @@ -0,0 +1,5 @@ +--- +"@solidjs/meta": patch +--- + +Render nullish children as an empty tag during SSR instead of the literal string `"undefined"`. `escape` passes non-string values through untouched, so `{value?.title}` emitted `undefined` when `value` had not resolved yet. diff --git a/src/index.tsx b/src/index.tsx index a10da4e..00ccd51 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -253,12 +253,15 @@ function renderTags(tags: Array) { ) .join(""); - const children = flattenChildren(tag.props.children); + // nullish children would otherwise be interpolated into the tag as the + // literal string "undefined" / "null", since `escape` passes non-strings + // through untouched + const children = flattenChildren(tag.props.children) ?? ""; if (tag.setting?.close) { return `<${tag.tag} data-sm="${tag.id}"${props}>${ // @ts-expect-error - tag.setting?.escape ? escape(children) : children || "" + tag.setting?.escape ? escape(children) : children }`; } return `<${tag.tag} data-sm="${tag.id}"${props}/>`;