Skip to content

Commit

Permalink
fix: only clear overlay root when assigning a renderer if needed (#7313
Browse files Browse the repository at this point in the history
…) (#7314)

Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan authored Apr 10, 2024
1 parent 6de801a commit 73b6ee3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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;
});
});

0 comments on commit 73b6ee3

Please sign in to comment.