lit: [ssr] breaks when using expressions in `` and `` tags
Description
A clear and concise description of what the bug is.
Steps to Reproduce
- 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")));
});
}
- 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
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 17 (8 by maintainers)
lit-labs/ssr@3.2.0 added server only templates which support
<title>and<html>for templates that only render during SSR.Circling back to the example given in the issue description, the server only template version would be:
This template is rendered by Lit SSR as plain HTML (without any Lit marker comments). Therefore it cannot be hydrated or re-rendered on the client. This is by design as it’s not possible to hydrate
<!doctype html>or<title>. One final note, server templates can contain client templates (e.g. html imported from ‘lit’), but client templates cannot contain server templates.Server only template documentation
Try them out, and please file issues (or re-open this one) if issues persist or new ones arise! Thank you!
should
<html>attrs be a special case in ssr-and-hydrate-only?@aomarks I can fix
<title>real quick