From d1e5e6f4182c7c99ce73f54c5e3012f367a5b5b9 Mon Sep 17 00:00:00 2001 From: Vladimir Malygin Date: Fri, 27 Sep 2024 18:18:43 +0300 Subject: [PATCH] fix(ilc): hard remove CSS link when an embedded application is unmounter --- ilc/client/CssTrackedApp.js | 2 +- ilc/client/CssTrackedApps.spec.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/ilc/client/CssTrackedApp.js b/ilc/client/CssTrackedApp.js index 8d06b65a8..c399fc038 100644 --- a/ilc/client/CssTrackedApp.js +++ b/ilc/client/CssTrackedApp.js @@ -47,7 +47,7 @@ export class CssTrackedApp { return newInstance; } - return new CssTrackedApp(newInstance, this.#cssLinkUri, this.#delayCssRemoval).getDecoratedApp(); + return new CssTrackedApp(newInstance, this.#cssLinkUri, false).getDecoratedApp(); }); }; diff --git a/ilc/client/CssTrackedApps.spec.js b/ilc/client/CssTrackedApps.spec.js index f73f022f8..a533a037c 100644 --- a/ilc/client/CssTrackedApps.spec.js +++ b/ilc/client/CssTrackedApps.spec.js @@ -92,6 +92,29 @@ describe('CssTrackedApp', function () { }), ); }); + + it('should remove CSS link after createNew, mount, and unmount', async () => { + const returnValue = Math.random(); + const appOnCreateNew = createOriginalAppFake(Promise.resolve(returnValue)); + const originalApp = createOriginalAppFake(Promise.resolve(Math.random())); + originalApp.createNew = () => Promise.resolve(appOnCreateNew); + + const cssLink = 'data:text/css,'; + const cssWrap = new CssTrackedApp(originalApp, cssLink, false).getDecoratedApp(); + + const newApp = await cssWrap.createNew(); + + await newApp.mount(); + + let link = document.querySelector(`link[href="${cssLink}"]`); + expect(link).to.not.be.null; + expect(link.getAttribute(CssTrackedApp.linkUsagesAttribute)).to.equal('1'); + + await newApp.unmount(); + + link = document.querySelector(`link[href="${cssLink}"]`); + expect(link).to.be.null; + }); }); it('should add counter to css on mount', async () => {