From e1c06f6e26db462f46d8be69d2cabae5743caae5 Mon Sep 17 00:00:00 2001 From: Serhii Kulykov Date: Mon, 20 Jan 2025 14:08:18 +0200 Subject: [PATCH] fix: check if node is an element when removing slot attribute (#8533) --- .../src/vaadin-split-layout-mixin.js | 2 +- .../split-layout/test/split-layout.common.js | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/split-layout/src/vaadin-split-layout-mixin.js b/packages/split-layout/src/vaadin-split-layout-mixin.js index 9d1761e89bb..a96fad536a2 100644 --- a/packages/split-layout/src/vaadin-split-layout-mixin.js +++ b/packages/split-layout/src/vaadin-split-layout-mixin.js @@ -55,7 +55,7 @@ export const SplitLayoutMixin = (superClass) => /** @private */ _cleanupNodes(nodes) { nodes.forEach((node) => { - if (!(node.parentElement instanceof this.constructor)) { + if (node.nodeType === Node.ELEMENT_NODE && !(node.parentElement instanceof this.constructor)) { const slot = node.getAttribute('slot'); if (slot) { this[`_${slot}Child`] = null; diff --git a/packages/split-layout/test/split-layout.common.js b/packages/split-layout/test/split-layout.common.js index 1f75bfba7fb..a982959b770 100644 --- a/packages/split-layout/test/split-layout.common.js +++ b/packages/split-layout/test/split-layout.common.js @@ -1,6 +1,7 @@ import { expect } from '@vaadin/chai-plugins'; import { aTimeout, fixtureSync, nextFrame, nextRender, track } from '@vaadin/testing-helpers'; import sinon from 'sinon'; +import { html, render } from 'lit'; const initialSizes = { width: 128, height: 128 }; @@ -462,4 +463,24 @@ describe('moving nodes between layouts', () => { expect(second.getAttribute('slot')).to.equal('primary'); expect(first.getAttribute('slot')).to.equal('secondary'); }); + + describe('nested Lit template', () => { + let root; + + beforeEach(() => { + root = fixtureSync('
'); + }); + + it('should not throw when re-rendering child element conditionally', async () => { + const fooTpl = html`
Foo
`; + const nestedTpl = (foo) => (foo ? html`${fooTpl}` : html`
Bar
`); + const parentTpl = (foo) => html`${nestedTpl(foo)}`; + + render(parentTpl(true), root); + await nextFrame(); + + render(parentTpl(false), root); + await nextFrame(); + }); + }); });