diff --git a/CHANGELOG.md b/CHANGELOG.md index f91735a..e1369ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Date format : day/month/year - Fix for fade configuration (!66) - Added basic token conditions (Thanks to Putty) - Added ability to remove condition from actor sheet and core journal on click. +- Added some Tooltips loading optimizations (!62 Thanks to KitCat). - Added some Properties loading optimizations (!63 Thanks to KitCat). ## 1.13.0 - 24/08/2025 - Foundry v13 Compatibility (Thx to Litasa) diff --git a/system/scripts/misc/l5r5e-popup-manager.js b/system/scripts/misc/l5r5e-popup-manager.js index ce9a07c..250a5c3 100644 --- a/system/scripts/misc/l5r5e-popup-manager.js +++ b/system/scripts/misc/l5r5e-popup-manager.js @@ -19,6 +19,12 @@ export class L5r5ePopupManager { /** @type {HTMLElement} */ #container = null; + /** + * Increment number to ignore old tooltips if template is too long to load (#62) + * @type {number} + */ + #displayId = 0; + /** * @param {string|jQuery} selector - Selector or jQuery object for tooltip-bound elements. * @param {(event: MouseEvent) => Promise} callback - Async function returning tooltip HTML content. @@ -45,10 +51,24 @@ export class L5r5ePopupManager { .on("mouseenter.popup", async (event) => { $(this.#container).find("#l5r5e-tooltip-ct").remove(); + // Memory save + if (this.#displayId >= 200) { + this.#displayId = 0; + } + const currentDisplayId = ++this.#displayId; + + // Load the template, can take a while const tpl = await this.#callback(event); // Abort if no content or the target element is no longer in the DOM - if (!tpl || !document.body.contains(event.currentTarget)) return; + if (!tpl || !document.body.contains(event.currentTarget)) { + return; + } + + // If mismatched, that tpl is too old, the user already display another tooltip + if (this.#displayId !== currentDisplayId) { + return; + } $(this.#container).append( `
${tpl}
`