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

fix: only clear overlay root when assigning a renderer if needed (#7313) (CP: 24.3) #7314

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/overlay/src/vaadin-overlay-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,13 @@ export const OverlayMixin = (superClass) =>
this._oldOwner = owner;

const rendererChanged = this._oldRenderer !== renderer;
const hasOldRenderer = this._oldRenderer !== undefined;
this._oldRenderer = renderer;

const openedChanged = this._oldOpened !== opened;
this._oldOpened = opened;

if (rendererChanged) {
if (rendererChanged && hasOldRenderer) {
this.innerHTML = '';
// Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
// When clearing the rendered content, this part needs to be manually disposed of.
Expand Down
25 changes: 25 additions & 0 deletions packages/overlay/test/renderer.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,29 @@ describe('renderer', () => {
await nextRender();
expect(overlay.textContent.trim()).to.equal('');
});

it('should not clear the root on open when setting renderer', async () => {
const spy = sinon.spy(overlay, 'innerHTML', ['set']);
overlay.renderer = (root) => {
if (!root.innerHTML) {
root.appendChild(content);
}
};
overlay.opened = true;
await nextRender();
expect(spy.set).to.not.be.called;
});

it('should not re-render when opened after requesting content update', async () => {
const spy = sinon.spy(overlay, 'appendChild');
overlay.renderer = (root) => {
if (!root.innerHTML) {
root.appendChild(content);
}
};
overlay.requestContentUpdate();
overlay.opened = true;
await nextRender();
expect(spy).to.be.calledOnce;
});
});
Loading