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 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ function generateThemeFile(themeFolder, themeName, themeProperties, productionMo
themeFile += `
window.Vaadin = window.Vaadin || {};
window.Vaadin['${globalCssFlag}'] = window.Vaadin['${globalCssFlag}'] || [];
var cleanupObserver = new MutationObserver(
(mutations) => {
mutations.forEach((mutation) => {
mutation.removedNodes.forEach((node) => {
const index = window.Vaadin['${globalCssFlag}'].indexOf(node.shadowRoot);
if(index > -1) {
window.Vaadin['${globalCssFlag}'].splice(index, 1);
}
})
})
}
);
cleanupObserver.observe(document.body, {
childList: true
tomivirkki marked this conversation as resolved.
Show resolved Hide resolved
});
`;

// Don't format as the generated file formatting will get wonky!
Expand All @@ -265,7 +280,7 @@ window.Vaadin['${globalCssFlag}'] = window.Vaadin['${globalCssFlag}'] || [];
if (injectGlobal) {
${globalCssCode.join('')}
window.Vaadin['${globalCssFlag}'].push(target);
}
}
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"));

}
}