Skip to content

Commit

Permalink
Reduce layout thrashing in activateListeners phase of encounter track…
Browse files Browse the repository at this point in the history
…er update (#16470)
  • Loading branch information
Codas authored Sep 11, 2024
1 parent 3844e79 commit 4a5527f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/module/apps/sidebar/encounter-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class EncounterTrackerPF2e<TEncounter extends EncounterPF2e | null> exten

const encounter = this.viewed;
if (!encounter) return super.activateListeners($html);
const trackerPlaceholder = document.createElement("div");
tracker.replaceWith(trackerPlaceholder);

const tokenSetsNameVisibility = game.pf2e.settings.tokens.nameVisibility;
const allyColor = (c: CombatantPF2e<EncounterPF2e>) =>
Expand Down Expand Up @@ -129,7 +131,7 @@ export class EncounterTrackerPF2e<TEncounter extends EncounterPF2e | null> exten
}
}

this.refreshTargetDisplay(combatant);
this.refreshTargetDisplay(combatant, [tracker]);

// Hide names in the tracker of combatants with tokens that have unviewable nameplates
if (tokenSetsNameVisibility) {
Expand Down Expand Up @@ -180,19 +182,21 @@ export class EncounterTrackerPF2e<TEncounter extends EncounterPF2e | null> exten
}
}

trackerPlaceholder.replaceWith(tracker);
super.activateListeners($html);
}

/** Refresh the list of users targeting a combatant's token as well as the active state of the target toggle */
refreshTargetDisplay(combatantOrToken: CombatantPF2e | TokenDocumentPF2e): void {
refreshTargetDisplay(combatantOrToken: CombatantPF2e | TokenDocumentPF2e, trackers?: HTMLElement[]): void {
if (!this.viewed || !canvas.ready) return;

const { combatant, tokenDoc } = combatantAndTokenDoc(combatantOrToken);
if (combatant?.encounter !== this.viewed || tokenDoc?.combatant !== combatant) {
return;
}

for (const tracker of htmlQueryAll(document, "#combat, #combat-popout")) {
trackers ??= htmlQueryAll(document, "#combat, #combat-popout");
for (const tracker of trackers) {
const combatantRow = htmlQuery(tracker, `li.combatant[data-combatant-id="${combatant?.id ?? null}"]`);
if (!combatantRow) return;

Expand Down

0 comments on commit 4a5527f

Please sign in to comment.