From 6fbc7e7864559d36f3a4797022ebd5e649c77da7 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnier Date: Thu, 4 Jun 2026 23:20:23 +0200 Subject: [PATCH] fix(actor): check applicationPhase to prevent double effect application The previous solution used a flag, but it didn't persist across preparation cycles. This solution checks this.effects.applicationPhase directly. If phase is 'initial' or 'final', it means effects are already being applied, so we skip the super.prepareEmbeddedDocuments() call to avoid the 'phase has already completed' error. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- module/documents/actor.mjs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) 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(); } /**