-
Notifications
You must be signed in to change notification settings - Fork 966
[ssr] breaks when using expressions in <title>
and <html>
tags
#2441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the report, will look into this soon. |
@aomarks attributes for the html tag is another case that breaks const template = ({ lang }) => html`
<html lang="${lang}">
[...]
`; Do you want it as a separate issue or is this good enough? |
This one is fine, I'll update the title. |
<title>
tag<title>
and <html>
tags
<title>
and <html>
tags<title>
and <html>
tags
For Raw text elements won't parse out comment-like strings, they My hunch for the |
@aomarks I can fix |
I will only list stuff I find for now 😬 another breaking template const template = ({ foo }) => html`
[...]
<body foo="${foo}">
[...]
`; probably a similar case to html tag? |
Reopening to track the |
I'm not entirely sure that we can support bindings to import {render} from '../../lib/render-with-global-dom-shim.js';
import {template} from './app.js';
export function* renderPage(data) {
yield `
<html lang=${data.lang}>
<body>
`;
yield * render(template(data));
yield `
</body>
</html>
`;
} |
should |
I think needing to use a different template "system" for different parts of the dom seems very counterintuitive... would lead to user documentation like this: User DocsGenerally, you are required to use the template literal import { html } from 'lit-html';
pageTemplate.addBodyTopContent(html`
<p>stuff</p>
`); However, if you want to add something to the html outside of the body you must use plain html // warning using html` here will break
pageTemplate.addHeaderContent(`
<meta content="website" property="og:type">
`); Notesthat seems like a hard sell 😅 Especially as it will require you to manually join arrays, prevents you from using directives and generally, you can not reuse any of the existing knowledge of all the other templates... We could provide a string template literal tricky situation - I wonder if that is "impossible" in next, nuxt, ... as well? 🤔 |
I understand that it would be frustrating, but I'm guessing that there might be some very tricky issues to solve here. lit-ssr is designed to SSR templates that would have been client-rendered. You wouldn't have rendered |
ok, I have a rather simple workaround... (at least for a static site generator) which I think would be ok as an end-user API so for tags like so a page template would look something like this render(data) {
return html`
<!DOCTYPE html>
<html-server-only lang="${data.lang}">
<head>...</head>
<body-server-only class=${classMap(data.cssClasses)}>
${data.content()}
</body-server-only>
</html-server-only>
`;
} with that, the lit ssr rendering works as expected and before we actually save the file to disk we remove the this probably means you can NOT hydrate templates if they or their sub-templates are using a that is good enough for me for now 🤗 if lit could update a full html page if new data or new templates get rendered... then it would enable SPA like navigation by sending a new template result and rendering it... might be interesting but probably a different issue/discussion |
Augustine and I have been talking about this, and I think there's value in having server-only templates that can render the full page but that don't emit parts for hydration (i.e. we won't emit any Lit comments), and that do support rendering the entire document. We're looking into some approaches for this. |
We have a customer at a discussion site who wants SSR-only templates too, to replace their custom server template system. |
lit-labs/ssr@3.2.0 added server only templates which support 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 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! |
I think you can wrap // import { html, unsafeStatic } from 'lit/static-html.js' // get the unstatic version of html
let hello = 'hello'
return html`
${unsafeStatic(
`<title>${hello}</title>`,
)}
` |
Description
A clear and concise description of what the bug is.
Steps to Reproduce
test.js
node test.js
Expected Results
the ssr output
Actual Results
Browsers Affected
The text was updated successfully, but these errors were encountered: