diff --git a/src/core/drive/page_renderer.js b/src/core/drive/page_renderer.js index 7e6df4c4c..c2789639b 100644 --- a/src/core/drive/page_renderer.js +++ b/src/core/drive/page_renderer.js @@ -78,7 +78,7 @@ export class PageRenderer extends Renderer { await newStylesheetElements if (this.willRender) { - this.removeUnusedHeadStylesheetElements() + this.removeUnusedDynamicStylesheetElements() } } @@ -111,8 +111,8 @@ export class PageRenderer extends Renderer { } } - removeUnusedHeadStylesheetElements() { - for (const element of this.unusedHeadStylesheetElements) { + removeUnusedDynamicStylesheetElements() { + for (const element of this.unusedDynamicStylesheetElements) { document.head.removeChild(element) } } @@ -182,13 +182,9 @@ export class PageRenderer extends Renderer { await this.renderElement(this.currentElement, this.newElement) } - get unusedHeadStylesheetElements() { + get unusedDynamicStylesheetElements() { return this.oldHeadStylesheetElements.filter((element) => { - return !(element.hasAttribute("data-turbo-permanent") || - // Trix dynamically adds styles to the head that we want to keep around which have a - // `data-tag-name` attribute. Long term we should moves those styles to Trix's CSS file - // but for now we'll just skip removing them - element.hasAttribute("data-tag-name")) + return element.getAttribute("data-turbo-track") === "dynamic" }) } diff --git a/src/core/drive/progress_bar.js b/src/core/drive/progress_bar.js index 8ce398ca4..76e8e55a7 100644 --- a/src/core/drive/progress_bar.js +++ b/src/core/drive/progress_bar.js @@ -106,8 +106,6 @@ export class ProgressBar { createStylesheetElement() { const element = document.createElement("style") - element.id = ProgressBarID - element.setAttribute("data-turbo-permanent", "") element.type = "text/css" element.textContent = ProgressBar.defaultCSS if (this.cspNonce) { diff --git a/src/tests/fixtures/stylesheets/left.html b/src/tests/fixtures/stylesheets/left.html index 7da4b67f9..4931d33ec 100644 --- a/src/tests/fixtures/stylesheets/left.html +++ b/src/tests/fixtures/stylesheets/left.html @@ -4,13 +4,18 @@