Skip to content

Commit

Permalink
[lit-html] async-replace correctly re-renders when value is unchanged (
Browse files Browse the repository at this point in the history
…#4409)

* async-replace correctly re-renders when value is
unchanged. Fixes #4408.

* Update packages/lit-html/src/test/directives/async-replace_test.ts

Co-authored-by: Andrew Jakubowicz <spyr1014@gmail.com>

* Update packages/lit-html/src/test/directives/async-replace_test.ts

---------

Co-authored-by: Andrew Jakubowicz <spyr1014@gmail.com>
  • Loading branch information
Steve Orvell and AndrewJakubowicz committed Nov 21, 2023
1 parent af7e634 commit 1af7991
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/brave-frogs-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'lit-html': patch
'lit': patch
---

asyncReplace correctly re-renders when value is unchanged (#4408)
2 changes: 1 addition & 1 deletion packages/lit-html/src/directives/async-replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AsyncReplaceDirective extends AsyncDirective {
// If we've already set up this particular iterable, we don't need
// to do anything.
if (value === this.__value) {
return;
return noChange;
}
this.__value = value;
let i = 0;
Expand Down
24 changes: 24 additions & 0 deletions packages/lit-html/src/test/directives/async-replace_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ suite('asyncReplace', () => {
assert.equal(stripExpressionMarkers(container.innerHTML), '<div>bar</div>');
});

test('renders the same iterable value when re-rendered with no new value emitted', async () => {
const t = (iterable: any) => html`<div>${asyncReplace(iterable)}</div>`;
render(t(iterable), container);
assert.equal(stripExpressionMarkers(container.innerHTML), '<div></div>');

await iterable.push('hello');
assert.equal(
stripExpressionMarkers(container.innerHTML),
'<div>hello</div>'
);

render(t(iterable), container);
assert.equal(
stripExpressionMarkers(container.innerHTML),
'<div>hello</div>'
);

render(t(iterable), container);
assert.equal(
stripExpressionMarkers(container.innerHTML),
'<div>hello</div>'
);
});

test('renders new value over a pending iterable', async () => {
const t = (v: any) => html`<div>${v}</div>`;
// This is a little bit of an odd usage of directives as values, but it
Expand Down

0 comments on commit 1af7991

Please sign in to comment.