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:
@@ -27,16 +27,19 @@ export class VermineActor extends Actor {
|
|||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
prepareEmbeddedDocuments() {
|
prepareEmbeddedDocuments() {
|
||||||
// Prevent recursive effect application
|
// Check if effects are already being applied in this preparation cycle
|
||||||
// Foundry V11+ can sometimes call this multiple times in a preparation cycle
|
// In Foundry V11+, the parent prepareEmbeddedDocuments() calls applyActiveEffects()
|
||||||
if (this._preparingEffects) return;
|
// If this is called multiple times in the same cycle, we get the "phase already completed" error
|
||||||
this._preparingEffects = true;
|
const phase = this.effects?.applicationPhase;
|
||||||
|
|
||||||
try {
|
// If we're already in the middle of applying effects (initial or final phase),
|
||||||
super.prepareEmbeddedDocuments();
|
// don't call super as it would try to apply effects again
|
||||||
} finally {
|
if (phase === "initial" || phase === "final") {
|
||||||
delete this._preparingEffects;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If effects haven't been applied yet, proceed normally
|
||||||
|
super.prepareEmbeddedDocuments();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user