Open kyubisation opened 10 months ago
I think this is a known issue in lit-labs/ssr. I think the current theory is that SSR confuses the svg <title>
for the HTML <title>
. And the HTML <title>
tag is an invalid dynamic location during SSR (unless using a server template).
You can workaround your issue by using unsafeSVG
imported from lit/directives/unsafe-svg.js
. This tells SSR to trust the title svg element that you're inserting.
import { unsafeSVG } from 'lit/directives/unsafe-svg.js';
// ...
html`<svg>${unsafeSVG(`<title>${this.name}</title>`)}</svg>`
See working stackblitz example: https://stackblitz.com/edit/stackblitz-starters-tpsg7w?file=components%2Fsimple-greeting.ts
However keeping issue open because ideally you shouldn't need a workaround. Thank you for the report.
Thanks for the quick answer and workaround. I'll try it out.
In this specific instance, I was able to solve it via <title .textContent=${variable}></title>
.
Which package(s) are affected?
React (@lit/react), SSR (@lit-labs/ssr)
Description
When using
svg`<title>${this.name}</title>`
insiderender()
in an enclosing html template with an svg, it causes an error. It also breaks withhtml`<p>Hello <svg><title>${this.name}</title></svg></p>`
.Reproduction
https://stackblitz.com/edit/stackblitz-starters-ggktnm?file=components%2Fsimple-greeting.ts
Start with
npm install && npx next dev
and the error should be shown in console (after build) and in the preview window.Workaround
Replacing
svg`<title>${this.name}</title>`
withsvg`<title>text</title>`
works, but that is not an actual workaround.Is this a regression?
No or unsure. This never worked, or I haven't tried before.
Affected versions
lit 3.1.0, @lit/react 1.0.1, @lit-labs/nextjs 0.1.4
Browser/OS/Node environment
Browser: - OS: Linux Node.js: v18.18.0 npm: 9.4.2