Skip to content

Commit

Permalink
refactor: force Lit to perform first render synchronously (#8290)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Dec 13, 2024
1 parent 885d7e9 commit f8ee0ef
Show file tree
Hide file tree
Showing 25 changed files with 174 additions and 196 deletions.
11 changes: 0 additions & 11 deletions packages/combo-box/src/vaadin-combo-box-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,6 @@ export const ComboBoxMixin = (subclass) =>
theme,
itemClassNameGenerator,
});

// NOTE: in PolylitMixin, setProperties() waits for `hasUpdated` to be set.
// This means for the first opening, properties won't be set synchronously.
// Call `performUpdate()` in this case to mimic the Polymer version logic.
if (scroller.performUpdate && !scroller.hasUpdated) {
try {
scroller.performUpdate();
} catch (_) {
// Suppress errors in synchronous tests for pre-opened combo-box.
}
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions packages/combo-box/src/vaadin-combo-box-scroller-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,6 @@ export const ComboBoxScrollerMixin = (superClass) =>
el.className = '';
}

// NOTE: in PolylitMixin, setProperties() waits for `hasUpdated` to be set.
// However, this causes issues with virtualizer. So we enforce sync update.
if (el.performUpdate && !el.hasUpdated) {
el.performUpdate();
}

el.id = `${this.__hostTagName}-item-${index}`;
el.setAttribute('role', index !== undefined ? 'option' : false);
el.setAttribute('aria-selected', selected.toString());
Expand Down
11 changes: 11 additions & 0 deletions packages/component-base/src/polylit-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ const PolylitMixinImplementation = (superclass) => {
return result;
}

static get polylitConfig() {
return {
asyncFirstRender: false,
};
}

constructor() {
super();
this.__hasPolylitMixin = true;
Expand All @@ -214,6 +220,11 @@ const PolylitMixinImplementation = (superclass) => {
parentHost.$ ||= {};
parentHost.$[this.id] = this;
}

const { polylitConfig } = this.constructor;
if (!this.hasUpdated && !polylitConfig.asyncFirstRender) {
this.performUpdate();
}
}

/** @protected */
Expand Down
Loading

0 comments on commit f8ee0ef

Please sign in to comment.