Skip to content
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

async-replace correctly re-renders when value is unchanged #4409

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
26 changes: 26 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,32 @@ suite('asyncReplace', () => {
assert.equal(stripExpressionMarkers(container.innerHTML), '<div>bar</div>');
});

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

const wait = iterable.push('hello');
render(t(iterable), container);
await wait;
assert.equal(
stripExpressionMarkers(container.innerHTML),
'<div>hello</div>'
);
sorvell marked this conversation as resolved.
Show resolved Hide resolved

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

render(t(iterable), container);
assert.equal(
stripExpressionMarkers(container.innerHTML),
'<div>hello</div>'
);
AndrewJakubowicz marked this conversation as resolved.
Show resolved Hide resolved
});

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