Skip to content

[ssr] breaks when using expressions in <title> and <html> tags #2441

Description

@daKmoR

Description

A clear and concise description of what the bug is.

Steps to Reproduce

  1. Write this code in test.js
import { Readable } from "stream";
import { render } from "@lit-labs/ssr/lib/render-with-global-dom-shim.js";
import { html } from 'lit-html';

const template = ({ title }) => html`
  <html>
    <head>
      <!-- remove the next line and it works -->
      <title>${title}</title>
    </head>
    <body>
      <p>${title}</p>
    </body>
  </html>
`;

const ssrResult = render(template({ title: "hello" }));



/***** 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 test.js

Expected Results

the ssr output

Actual Results

$ node test.js
node:internal/process/esm_loader:94
    internalBinding('errors').triggerUncaughtException(
                              ^

Error: unexpected final partIndex: 1 !== 2
    at renderTemplateResult (file:///html/test-ssr/node_modules/@lit-labs/ssr/lib/render-lit-html.js:514:15)
    at renderTemplateResult.next (<anonymous>)
    at renderValue (file:///html/test-ssr/node_modules/@lit-labs/ssr/lib/render-lit-html.js:354:16)
    at renderValue.next (<anonymous>)
    at render (file:///html/test-ssr/node_modules/@lit-labs/ssr/lib/render-lit-html.js:336:12)
    at render.next (<anonymous>)
    at next (node:internal/streams/from:86:20)
    at Readable.readable._read (node:internal/streams/from:53:7)
    at Readable.read (node:internal/streams/readable:487:10)
    at flow (node:internal/streams/readable:1012:34)

Browsers Affected

  • Node 17
  • Node 16

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions