Skip to content

Commit 0cd87b7

Browse files
authored
Fix error when actors that are party members are deleted (#19178)
1 parent 8287c93 commit 0cd87b7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/module/apps/sidebar/actor-directory.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,24 @@ class ActorDirectoryPF2e extends fa.sidebar.tabs.ActorDirectory<ActorPF2e<null>>
5959
this.collection.filter((a): a is PartyPF2e<null> => a.isOfType("party") && a !== activeParty),
6060
(p) => p.sort,
6161
);
62-
return Object.assign(partContext, { activeParty, parties, extraFolders: this.#extraFolders });
62+
return Object.assign(partContext, {
63+
activeParty: this.#createPartyContext(activeParty),
64+
parties: parties.map((p) => this.#createPartyContext(p)),
65+
extraFolders: this.#extraFolders,
66+
});
67+
}
68+
69+
/**
70+
* Creates context data for the party, only including members that exist in the actor world collection.
71+
* It is possible for re-renders to occur before the party is reset, causing stale data to render.
72+
*/
73+
#createPartyContext(party: PartyPF2e | null): PartyContext | null {
74+
if (!party) return null;
75+
76+
return {
77+
...R.pick(party, ["id", "name", "img", "active"]),
78+
members: party.members.filter((m) => game.actors.has(m.id)),
79+
};
6380
}
6481

6582
protected override async _prepareFooterContext(
@@ -280,4 +297,8 @@ interface ActorSidebarDropData extends DropCanvasData<"actor", ActorPF2e> {
280297
fromParty?: string;
281298
}
282299

300+
interface PartyContext extends Pick<PartyPF2e, "id" | "name" | "img" | "active"> {
301+
members: CreaturePF2e[];
302+
}
303+
283304
export { ActorDirectoryPF2e };

0 commit comments

Comments
 (0)