Skip to content

Commit 4b7c160

Browse files
authored
fix: do not re-render when setting sync property to the same value (#8223)
1 parent eb8470d commit 4b7c160

File tree

10 files changed

+50
-17
lines changed

10 files changed

+50
-17
lines changed

packages/component-base/src/polylit-mixin.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55
*/
66
import { dedupeMixin } from '@open-wc/dedupe-mixin';
7+
import { notEqual } from 'lit';
78
import { get, set } from './path-utils.js';
89

910
const caseMap = {};
@@ -101,12 +102,15 @@ const PolylitMixinImplementation = (superclass) => {
101102
get: defaultDescriptor.get,
102103
set(value) {
103104
const oldValue = this[name];
104-
this[key] = value;
105-
this.requestUpdate(name, oldValue, options);
106105

107-
// Enforce synchronous update
108-
if (this.hasUpdated) {
109-
this.performUpdate();
106+
if (notEqual(value, oldValue)) {
107+
this[key] = value;
108+
this.requestUpdate(name, oldValue, options);
109+
110+
// Enforce synchronous update
111+
if (this.hasUpdated) {
112+
this.performUpdate();
113+
}
110114
}
111115
},
112116
configurable: true,
@@ -115,21 +119,17 @@ const PolylitMixinImplementation = (superclass) => {
115119
}
116120

117121
if (options.readOnly) {
118-
const setter = defaultDescriptor.set;
122+
const setter = result.set;
119123

120124
this.addCheckedInitializer((instance) => {
121125
// This is run during construction of the element
122126
instance[`_set${upper(name)}`] = function (value) {
123127
setter.call(instance, value);
124-
125-
if (options.sync) {
126-
this.performUpdate();
127-
}
128128
};
129129
});
130130

131131
result = {
132-
get: defaultDescriptor.get,
132+
get: result.get,
133133
set() {
134134
// Do nothing, property is read-only.
135135
},

packages/component-base/src/resize-mixin.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
88
const observer = new ResizeObserver((entries) => {
99
setTimeout(() => {
1010
entries.forEach((entry) => {
11+
if (!entry.target.isConnected) {
12+
return;
13+
}
14+
1115
// Notify child resizables, if any
1216
if (entry.target.resizables) {
1317
entry.target.resizables.forEach((resizable) => {

packages/component-base/test/polylit-mixin.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,20 @@ describe('PolylitMixin', () => {
10511051
expect(element.hasAttribute('helper')).to.be.true;
10521052
});
10531053

1054+
it('should not reflect immediately when setting a read-only sync property to the same value', () => {
1055+
element._setOpened(true);
1056+
element._setHelper('foo'); // async property
1057+
element._setOpened(true); // sync property
1058+
expect(element.hasAttribute('helper')).to.be.false;
1059+
});
1060+
1061+
it('should not reflect immediately when setting sync property to the same value', () => {
1062+
element.disabled = true;
1063+
element._setHelper('foo'); // async property
1064+
element.disabled = true; // sync property
1065+
expect(element.hasAttribute('helper')).to.be.false;
1066+
});
1067+
10541068
it('should only call ready callback once during initialization', () => {
10551069
expect(element.count).to.equal(1);
10561070
});

packages/date-picker/src/vaadin-date-picker-mixin.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,10 +1211,7 @@ export const DatePickerMixin = (subclass) =>
12111211
if (!dateEquals(this.__enteredDate, date)) {
12121212
this.__enteredDate = date;
12131213
}
1214-
} else if (this.__enteredDate != null) {
1215-
// Do not override initial undefined value with null
1216-
// to avoid triggering a Lit update that can cause
1217-
// other scheduled properties to flush too early.
1214+
} else {
12181215
this.__enteredDate = null;
12191216
}
12201217
}

packages/field-base/src/input-mixin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const InputMixin = dedupingMixin(
6363
type: Boolean,
6464
value: false,
6565
observer: '_hasInputValueChanged',
66+
sync: true,
6667
},
6768
};
6869
}

packages/grid/src/vaadin-grid-column-group-mixin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const GridColumnGroupMixin = (superClass) =>
4141
width: {
4242
type: String,
4343
readOnly: true,
44+
sync: true,
4445
},
4546

4647
/** @private */

packages/grid/src/vaadin-grid-column-mixin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,16 @@ export const ColumnBaseMixin = (superClass) =>
177177
_emptyCells: Array,
178178

179179
/** @private */
180-
_headerCell: Object,
180+
_headerCell: {
181+
type: Object,
182+
sync: true,
183+
},
181184

182185
/** @private */
183-
_footerCell: Object,
186+
_footerCell: {
187+
type: Object,
188+
sync: true,
189+
},
184190

185191
/** @protected */
186192
_grid: Object,

packages/grid/src/vaadin-grid-sorter-mixin.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ export const GridSorterMixin = (superClass) =>
117117
/** @protected */
118118
connectedCallback() {
119119
super.connectedCallback();
120+
121+
if (this.performUpdate) {
122+
// Force Lit's first render to be synchronous to ensure
123+
// _pathOrDirectionChanged is triggered before grid's
124+
// __applySorters, as it is in Polymer.
125+
this.performUpdate();
126+
}
127+
120128
if (this._grid) {
121129
this._grid.__applySorters();
122130
} else {

packages/item/src/vaadin-item-mixin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const ItemMixin = (superClass) =>
3838
value: false,
3939
reflectToAttribute: true,
4040
observer: '_selectedChanged',
41+
sync: true,
4142
},
4243

4344
/** @private */

packages/select/src/vaadin-select-base-mixin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export const SelectBaseMixin = (superClass) =>
9797
value: '',
9898
notify: true,
9999
observer: '_valueChanged',
100+
sync: true,
100101
},
101102

102103
/**

0 commit comments

Comments
 (0)