Skip to content

[ssr] empty lit templates result in invalid html "<?>" #2470

@daKmoR

Description

@daKmoR

Description

empty templates result in <?> in the html which is an invalid tag... it can break parsing (at least it breaks sax-wasm)

Steps to Reproduce

  1. Write this code
const template = ({ title, lang }) => html`
  <p>${title}</p>
  ${html``}
  ${''} 
  <p>more</p>
`;

const ssrResult = render(template({ title: "hello", lang: 'en' }));


/***** HELPERS */
const stream = Readable.from(ssrResult);
const ssrString = await streamToString(stream);

console.log(ssrString);

function streamToString(stream) {
  const chunks = [];
  return new Promise((resolve, reject) => {
    stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
    stream.on("error", (err) => reject(err));
    stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
  });
}
  1. execute it via node

Expected Results

no invalid tags in the html

<!--lit-part cI7PGs8mxHY=-->
  <p><!--lit-part-->hello<!--/lit-part--></p>
  <!--lit-part BRUAAAUVAAA=--><!--/lit-part-->
  <!--lit-part--><!--/lit-part-->
  <p>more</p>
<!--/lit-part-->

Actual Results

the empty template literal has <?> as content

<!--lit-part cI7PGs8mxHY=-->
  <p><!--lit-part-->hello<!--/lit-part--></p>
  <!--lit-part BRUAAAUVAAA=--><?><!--/lit-part-->
  <!--lit-part--><!--/lit-part-->
  <p>more</p>
<!--/lit-part-->

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions