Skip to content

fix: render nullish meta children as empty instead of "undefined" - #71

Open
birkskyum wants to merge 1 commit into
solidjs:0.xfrom
birkskyum:fix/nullish-meta-children
Open

birkskyum wants to merge 1 commit into
solidjs:0.xfrom
birkskyum:fix/nullish-meta-children

Conversation

@birkskyum

@birkskyum birkskyum commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Problem

During SSR, a nullish child is interpolated into the tag as the literal string "undefined":

<Title>{pill()?.title}</Title>

If pill() has not resolved when the shell flushes, the emitted HTML is:

<title>undefined</title>

escape early-returns for non-string values, so escape(undefined) gives back undefined, which the template literal then stringifies. The unescaped branch already guarded against this with children || ""; the escaped branch (used by Title) did not.

Fix

Guard once at the flattenChildren call so both branches behave the same:

-      const children = flattenChildren(tag.props.children);
+      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
         }</${tag.tag}>`;
       }

?? "" rather than || "" so that 0 and false still render, which the previous unescaped branch dropped.

Verification

pnpm test:unit (15 passed), pnpm build and pnpm test:types all clean.

Also verified end to end in a SolidStart 2.0 app, on a route whose <Title> reads an unresolved createAsync. Before the change the SSR HTML contained <title>undefined</title>; after it contains <title></title>.

Context: this is the mechanism behind solidjs/solid-start#1881, where several users saw undefined as their page title in crawlers. This change does not make async titles work under streaming SSR (that needs deferStream on the createAsync), but an empty title is a much better failure mode than a wrong one.

Notes

No test added: the repo's vitest setup is jsdom with generate: 'dom', so renderTags has no SSR coverage to extend, and the most recent change to this function (3cbd12c) was likewise source-only. Happy to add an SSR test config if you would like one.

Fixes #73.

`escape` returns non-string values untouched, so a nullish child was
interpolated into the tag as the literal string "undefined". Guard once
at the `flattenChildren` call so both the escaped and unescaped branches
behave the same.
@ryansolid ryansolid added the 1.x Solid 1 line (0.29.x, main) label Nov 17, 2026 — with Claude

Copy link
Copy Markdown
Member

Thank you for this. Closing as part of the Solid 2.0 cleanup: @solidjs/meta 2.0.0 is a rewrite on top of Solid 2.0's built-in head registry, and the 0.x line on the old main isn't getting further changes. If the same problem shows up on 2.0.0, please open an issue or a PR against the current main.


Generated by Claude Code

@ryansolid ryansolid closed this Nov 17, 2026
@ryansolid ryansolid reopened this Nov 17, 2026

Copy link
Copy Markdown
Member

Reopened, sorry about the noise. This is a non-breaking fix for the Solid 1 line, which now lives on the 0.x branch, so it stays open for a 0.29.x release.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.x Solid 1 line (0.29.x, main)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSR: nullish Title children serialize as literal "undefined"

3 participants