From 02aabbea361d1741935f1ffd098c66488f78b47e Mon Sep 17 00:00:00 2001 From: LeRatierBretonnier Date: Thu, 4 Jun 2026 23:20:40 +0200 Subject: [PATCH] fix(hooks): delay editMode flag setting to avoid phase error on createActor The createActor hook was calling actor.setFlag() immediately, which triggered updateActor -> prepareData -> prepareEmbeddedDocuments() -> applyActiveEffects(). Since the actor had already gone through data preparation during creation, the effects had already been applied, causing the 'phase already completed' error. Solution: Use setTimeout(..., 0) to defer the flag setting until after the current preparation cycle is complete. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- module/system/hooks.mjs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/module/system/hooks.mjs b/module/system/hooks.mjs index ec95f71..7d77bf3 100644 --- a/module/system/hooks.mjs +++ b/module/system/hooks.mjs @@ -147,7 +147,17 @@ export const registerHooks = function () { }*/ } }); - Hooks.on("createActor", function (actor, options, id) { - actor.setFlag("world", "editMode", true) + Hooks.on("createActor", async function (actor, options, id) { + // Delay flag setting to avoid the "phase already completed" error + // When an actor is created, it goes through data preparation which applies effects. + // If we call setFlag() immediately, it triggers updateActor -> prepareData -> + // prepareEmbeddedDocuments() which tries to apply effects again, causing the error. + // By using setTimeout with 0ms, we defer the flag setting until after the current + // preparation cycle is complete. + setTimeout(() => { + actor.setFlag("world", "editMode", true).catch(err => { + console.error("Vermine2047 | Failed to set editMode flag:", err); + }); + }, 0); }) } \ No newline at end of file