From 174aceeb915d3f65162a855f4fd77177002bcaa0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 7 Mar 2026 16:06:18 -0700 Subject: [PATCH] Prevent the content from rerendering when it doesn't get any changes, allowing in-progress edits (closes #31) --- module/apps/AttributeOnlyPlayerSheet.mjs | 9 ++++++++ module/apps/PlayerSheet.mjs | 26 +++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/module/apps/AttributeOnlyPlayerSheet.mjs b/module/apps/AttributeOnlyPlayerSheet.mjs index 3b811fd..41ee130 100644 --- a/module/apps/AttributeOnlyPlayerSheet.mjs +++ b/module/apps/AttributeOnlyPlayerSheet.mjs @@ -14,4 +14,13 @@ export class AttributeOnlyPlayerSheet extends PlayerSheet { return parts; }; // #endregion Options + + // #region Lifecycle + _configureRenderOptions(options) { + super._configureRenderOptions(options); + + // don't attempt to rerender the content + options.parts = options.parts?.filter(partID => partID !== `content`); + }; + // #endregion Lifecycle }; diff --git a/module/apps/PlayerSheet.mjs b/module/apps/PlayerSheet.mjs index 84fb281..a1b8069 100644 --- a/module/apps/PlayerSheet.mjs +++ b/module/apps/PlayerSheet.mjs @@ -5,7 +5,16 @@ import { TAFDocumentSheetConfig } from "./TAFDocumentSheetConfig.mjs"; const { HandlebarsApplicationMixin } = foundry.applications.api; const { ActorSheetV2 } = foundry.applications.sheets; -const { getProperty } = foundry.utils; +const { getProperty, hasProperty } = foundry.utils; + +const propertyToParts = { + "name": [`header`], + "img": [`header`], + "system.attr": [`attributes`], + "system.attr.value": [`attributes`, `content`], + "system.attr.max": [`attributes`, `content`], + "system.content": [`content`], +}; export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { @@ -95,6 +104,21 @@ export class PlayerSheet extends HandlebarsApplicationMixin(ActorSheetV2) { return controls; }; + _configureRenderOptions(options) { + // Only rerender the parts of the app that got changed + if (options.renderContext === `updateActor`) { + const parts = new Set(); + for (const property in propertyToParts) { + if (hasProperty(options.renderData, property)) { + propertyToParts[property].forEach(partID => parts.add(partID)); + }; + }; + options.parts = options.parts?.filter(part => !parts.has(part)) ?? Array.from(parts); + }; + + super._configureRenderOptions(options); + }; + async close() { this.#attributeManager?.close(); this.#attributeManager = null;