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 <vibe@mistral.ai>
This commit is contained in:
2026-06-04 23:20:23 +02:00
parent 308073877b
commit 6fbc7e7864
+11 -8
View File
@@ -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();
}
/**