Skip to content

Commit a171c8f

Browse files
asyncLizcopybara-github
authored andcommitted
fix(decorators): ariaProperty not triggering re-renders from data changes
PiperOrigin-RevId: 469824174
1 parent 30c95ae commit a171c8f

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

decorators/aria-property.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,17 @@ export function ariaProperty<E extends ReactiveElement, K extends keyof E&
4747
set(this: ReactiveElement, value: unknown) {
4848
// Coerce non-string values to a string
4949
const strValue = String(value ?? '');
50-
const oldValue = this.dataset[property];
51-
if (strValue === oldValue) {
52-
return;
53-
}
54-
5550
if (strValue) {
5651
this.dataset[property] = strValue;
5752
} else {
5853
delete this.dataset[property];
5954
}
6055

61-
this.requestUpdate(property, oldValue);
56+
// lit will call this setter whenever the data-* attribute changes.
57+
// However, this.dataset[property] will automatically be updated to the
58+
// current value. To avoid bugs, always request an update regardless of
59+
// the old value.
60+
this.requestUpdate();
6261
}
6362
});
6463

decorators/test/aria-property_test.ts

-10
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,4 @@ describe('@ariaProperty', () => {
101101
.withContext('boolean should coerce to string')
102102
.toBe('true');
103103
});
104-
105-
it('should not request an update if the value stays the same', async () => {
106-
const value = 'Aria label';
107-
element.ariaLabel = value;
108-
await element.updateComplete;
109-
element.ariaLabel = value;
110-
expect(element.isUpdatePending)
111-
.withContext('there should not be an update pending')
112-
.toBeFalse();
113-
});
114104
});

0 commit comments

Comments
 (0)