fix: render nullish meta children as empty instead of "undefined" - #71
Open
birkskyum wants to merge 1 commit into
Open
fix: render nullish meta children as empty instead of "undefined"#71birkskyum wants to merge 1 commit into
birkskyum wants to merge 1 commit into
Conversation
`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.
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
During SSR, a nullish child is interpolated into the tag as the literal string
"undefined":If
pill()has not resolved when the shell flushes, the emitted HTML is:escapeearly-returns for non-string values, soescape(undefined)gives backundefined, which the template literal then stringifies. The unescaped branch already guarded against this withchildren || ""; the escaped branch (used byTitle) did not.Fix
Guard once at the
flattenChildrencall so both branches behave the same:?? ""rather than|| ""so that0andfalsestill render, which the previous unescaped branch dropped.Verification
pnpm test:unit(15 passed),pnpm buildandpnpm test:typesall clean.Also verified end to end in a SolidStart 2.0 app, on a route whose
<Title>reads an unresolvedcreateAsync. 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
undefinedas their page title in crawlers. This change does not make async titles work under streaming SSR (that needsdeferStreamon thecreateAsync), 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', sorenderTagshas 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.