Skip to content

Commit b3b5ece

Browse files
authored
Merge 1399080 into a1f8c34
2 parents a1f8c34 + 1399080 commit b3b5ece

4 files changed

Lines changed: 41 additions & 1 deletion

File tree

.changeset/hot-rabbits-promise.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'lit-html': patch
3+
'lit': patch
4+
---
5+
6+
`static-html` no longer adds an item to `TemplateResult`'s value array for the last consumed static value. This fixes an error with server-side rendering of static html.

packages/labs/ssr/src/test/integration/tests/basic.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import '@lit-labs/ssr-client/lit-element-hydrate-support.js';
88

99
import {html, noChange, nothing, Part} from 'lit';
10+
import {html as staticHtml, literal} from 'lit/static-html.js';
1011
import {
1112
directive,
1213
Directive,
@@ -4251,6 +4252,28 @@ export const tests: {[name: string]: SSRTest} = {
42514252
};
42524253
},
42534254

4255+
/******************************************************
4256+
* Static html tests
4257+
******************************************************/
4258+
4259+
'Static html': {
4260+
render(x: unknown) {
4261+
const tagName = x === 'foo' ? literal`div` : literal`p`;
4262+
return staticHtml`<${tagName}>${x}</${tagName}>`;
4263+
},
4264+
expectations: [
4265+
{
4266+
args: ['foo'],
4267+
html: '<div>foo</div>',
4268+
},
4269+
{
4270+
args: ['foo2'],
4271+
html: '<p>foo2</p>',
4272+
},
4273+
],
4274+
stableSelectors: [],
4275+
},
4276+
42544277
/******************************************************
42554278
* AsyncDirective tests
42564279
******************************************************/

packages/lit-html/src/static.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ export const withStatic =
131131
s += staticValue + strings[++i];
132132
hasStatics = true;
133133
}
134-
dynamicValues.push(dynamicValue);
134+
// If the last value is static, we don't need to push it.
135+
if (i !== l) {
136+
dynamicValues.push(dynamicValue);
137+
}
135138
staticStrings.push(s);
136139
i++;
137140
}

packages/lit-html/src/test/static_test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,12 @@ suite('static', () => {
177177
'<div>[object Object]</div>'
178178
);
179179
});
180+
181+
test('static html should not add value for consumed static expression', () => {
182+
const tagName = literal`div`;
183+
const template = html`<${tagName}>${'foo'}</${tagName}>`;
184+
assert.equal(template.values.length, 1);
185+
const template2 = html`<${tagName}>${'foo'}</${tagName}>${'bar'}`;
186+
assert.equal(template2.values.length, 2);
187+
});
180188
});

0 commit comments

Comments
 (0)