lit / lit

Lit is a simple library for building fast, lightweight web components.
https://lit.dev
BSD 3-Clause "New" or "Revised" License
18.53k stars 914 forks source link

[lit-testing]: ssr fixtures unable to render iterables #4739

Open KonnorRogers opened 4 weeks ago

KonnorRogers commented 4 weeks ago

Which package(s) are affected?

SSR (@lit-labs/ssr)

Description

When I use an iterable like an array in Lit SSR Web Test Runner plugin, I get the following error:

Error: invalid template strings array
    at N (file:///Users/konnor/projects/lit-ssr-global-xjrrzs/node_modules/lit-html/node/lit-html.js:6:836)
    at U (file:///Users/konnor/projects/lit-ssr-global-xjrrzs/node_modules/lit-html/node/lit-html.js:6:1535)
    at getTemplateOpcodes (file:///Users/konnor/projects/lit-ssr-global-xjrrzs/node_modules/@lit-labs/ssr/lib/render-value.js:119:31)
    at renderTemplateResult (file:///Users/konnor/projects/lit-ssr-global-xjrrzs/node_modules/@lit-labs/ssr/lib/render-value.js:454:17)
    at renderTemplateResult.next (<anonymous>)
    at renderValue (file:///Users/konnor/projects/lit-ssr-global-xjrrzs/node_modules/@lit-labs/ssr/lib/render-value.js:409:16)
    at renderValue.next (<anonymous>)
    at renderValue (file:///Users/konnor/projects/lit-ssr-global-xjrrzs/node_modules/@lit-labs/ssr/lib/render-value.js:427:24)
    at renderValue.next (<anonymous>)
    at renderTemplateResult (file:///Users/konnor/projects/lit-ssr-global-xjrrzs/node_modules/@lit-labs/ssr/lib/render-value.js:476:24)

Reproduction

https://github.com/KonnorRogers/lit-ssr-iterable-bug-reproduction

Workaround

None that ive found, besides manually iterating and creating nodes.

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

3.2.0

Browser/OS/Node environment

➜  lit-ssr-global-xjrrzs git:(main) npm ls lit
node-starter@0.0.0 /Users/konnor/projects/lit-ssr-global-xjrrzs
├─┬ @lit-labs/ssr-client@1.1.7
│ └── lit@3.2.0 deduped
├─┬ @lit-labs/ssr@3.2.2
│ └── lit@3.2.0 deduped
├─┬ @lit-labs/testing@0.2.4
│ └── lit@3.2.0 deduped
└── lit@3.2.0

Node 20.9.0 MacOS 14.5 Browser N/A Web Test Runner: 0.18.3

augustjk commented 4 weeks ago

Thank you for the report. This occurs specifically because the iterable contains TemplateResults made with the html tag function. The annoying limitation with the way the testing plugin works is that all expression values need to be serializable which template results are not. See https://github.com/lit/lit/issues/4015