diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 4f40017..55fc690 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -27,16 +27,19 @@ export class VermineActor extends Actor { /** @override */ prepareEmbeddedDocuments() { - // Prevent recursive effect application - // Foundry V11+ can sometimes call this multiple times in a preparation cycle - if (this._preparingEffects) return; - this._preparingEffects = true; + // Check if effects are already being applied in this preparation cycle + // In Foundry V11+, the parent prepareEmbeddedDocuments() calls applyActiveEffects() + // If this is called multiple times in the same cycle, we get the "phase already completed" error + const phase = this.effects?.applicationPhase; - try { - super.prepareEmbeddedDocuments(); - } finally { - delete this._preparingEffects; + // If we're already in the middle of applying effects (initial or final phase), + // don't call super as it would try to apply effects again + if (phase === "initial" || phase === "final") { + return; } + + // If effects haven't been applied yet, proceed normally + super.prepareEmbeddedDocuments(); } /**