From 1535e07f77b8fdf8729c94b080370fabe4eb4f7b Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 9 Feb 2025 16:26:52 -0700 Subject: [PATCH] Restore the style cache in a way that works for multiple components and prevents the jittering on Application rerender --- .../elements/mixins/StyledShadowElement.mjs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/module/Apps/elements/mixins/StyledShadowElement.mjs b/module/Apps/elements/mixins/StyledShadowElement.mjs index 75de31b..e5ef291 100644 --- a/module/Apps/elements/mixins/StyledShadowElement.mjs +++ b/module/Apps/elements/mixins/StyledShadowElement.mjs @@ -11,9 +11,9 @@ export function StyledShadowElement(Base) { /** * The stringified CSS to use - * @type {string} + * @type {Map} */ - static _styles; + static _styles = new Map(); /** * The HTML element of the stylesheet @@ -48,11 +48,17 @@ export function StyledShadowElement(Base) { _getStyles() { // TODO: Cache the CSS content in a more sane way that doesn't break - fetch(`./systems/${game.system.id}/templates/${this.constructor._stylePath}`) - .then(r => r.text()) - .then(t => { - this._style.innerHTML = t; - }); + const stylePath = this.constructor._stylePath; + if (this.constructor._styles.has(stylePath)) { + this._style.innerHTML = this.constructor._styles.get(stylePath); + } else { + fetch(`./systems/${game.system.id}/templates/${stylePath}`) + .then(r => r.text()) + .then(t => { + this.constructor._styles.set(stylePath, t); + this._style.innerHTML = t; + }); + } }; }; };