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: Remove removed items from array #11635

Merged
merged 5 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,13 @@ window.Vaadin['${globalCssFlag}'] = window.Vaadin['${globalCssFlag}'] || [];
if (injectGlobal) {
${globalCssCode.join('')}
window.Vaadin['${globalCssFlag}'].push(target);
}

const eventTarget = (target instanceof ShadowRoot) ? target.host : target;
eventTarget.addEventListener('DOMNodeRemoved', event => {
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved
pleku marked this conversation as resolved.
Show resolved Hide resolved
const index = window.Vaadin['${globalCssFlag}'].indexOf(target);
window.Vaadin['${globalCssFlag}'].splice(index, 1);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If/when using an observer instead, it can be disconnected after the clean-up

}
if (!document['${componentCssFlag}']) {
${componentCssCode.join('')}
document['${componentCssFlag}'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,22 @@ public void stylesCssImport_externalLinkAddedToShadowroot() {
Assert.assertTrue("Missing link for external url", linkUrls
.contains("https://fonts.googleapis.com/css?family=Itim"));
}

@Test
public void removingEmbeddedComponent_arrayIsCleaned() {
open();
checkLogsForErrors();
Assert.assertEquals(
"Both embedded components should have registered globalCss", 2l,
getCommandExecutor().executeScript(
"return window.Vaadin['_vaadintheme_embedded-theme_globalCss'].length"));
getCommandExecutor()
.executeScript("document.getElementById('second').remove()");

Assert.assertEquals(
"After removal of second should have removed its globalCss", 1l,
getCommandExecutor().executeScript(
"return window.Vaadin['_vaadintheme_embedded-theme_globalCss'].length"));

}
}