Why is this update causing a duplicate Actor sheet to be opened?

On my ActorSheetShell.svelte I have a button:
<i class="fas fa-lock" on:click="{toggleLock}" />
<i class="fas fa-lock" on:click="{toggleLock}" />
Which updates a boolean on the Actor sheet system:
function toggleLock() {
$doc.update(
{
["system.inventoryLocked"]: !$doc.system.inventoryLocked,
},
{
diff: true,
diffData: true,
diffSystem: true,
render: false,
}
);
}
function toggleLock() {
$doc.update(
{
["system.inventoryLocked"]: !$doc.system.inventoryLocked,
},
{
diff: true,
diffData: true,
diffSystem: true,
render: false,
}
);
}
But for some reason that triggers an opening of the Actor sheet. Any clues?
5 Replies
TyphonJS (Michael)
I have no idea... Unfortunately I can't mind read or remotely intuit your code, so have no idea where the problem lies. Perhaps add a console log & trace statement to the main script area of ActorSheetShell and take a look at the stack traces.
Wasp
Wasp2y ago
You want on:click={() => toggleLock()} maybe
TyphonJS (Michael)
You only need to provide an additional inline function when forwarding on data inside the template like in an each iteration / providing additional parameters to the invoked function. Hard to say what is going on as there is not enough information on where the "phantom" actor sheet invocation is coming from. Perhaps you need to consume that click event.
<i class="fas fa-lock" on:click|preventDefault|stopPropagation="{toggleLock}" /> You might have another listener somewhere that gets triggered. Hence why the debug trace when the sheet opens will give some insight on where the phantom trigger is coming from...
geoidesic
geoidesicOP2y ago
I haven't added any other listeners but I changed the toggleLock function to this, as per your idea, which seemed to solve that problem
function toggleLock(event) {
event.stopPropagation();
event.preventDefault();
$doc.update(
{
["system.inventoryLocked"]: !$doc.system.inventoryLocked,
},
{
diff: true,
diffData: true,
diffSystem: true,
}
);
}
function toggleLock(event) {
event.stopPropagation();
event.preventDefault();
$doc.update(
{
["system.inventoryLocked"]: !$doc.system.inventoryLocked,
},
{
diff: true,
diffData: true,
diffSystem: true,
}
);
}
Something else (related?) that is happening is that if I double-click the token, it opens up a character sheet (A) which says [token] top left in the header bar, which opens independently of the one that opens from the game actors panel (B). Once I've opened A and closed it, if I make any updates to the actor via B, then sheet A will spring open. Changes made in the A do not reflect in B (ever). A changes made in B reflects in A immediately as it springs open, but not once it is open. This is how I register the ActorSheet. I haven't registered any other listeners that should open a character sheet afaik:
Hooks.once("init", async () => {
console.log("SURGE | Starting Surge VTTRPG System");

Actors.registerSheet("surge", SurgeActorSheet, {
makeDefault: true,
});
Hooks.once("init", async () => {
console.log("SURGE | Starting Surge VTTRPG System");

Actors.registerSheet("surge", SurgeActorSheet, {
makeDefault: true,
});
Any insight into what might cause this behaviour?
No description
TyphonJS (Michael)
No idea. You should update to the latest TRL / svelte-standard. Make the few updates required by the latest TRL. Try things again. Then put console.trace() statements in the path of the SurgeActorSheet opening as mentioned above. The rough order of things is that: - You wrote buggy / inaccurate code. - You misunderstand how the Foundry API works. - You misunderstand how TRL / Svelte works. - There is a bug in Foundry. - Lastly there is an off chance that there is a bug in TRL (can't help w/ that until you update to the latest TRL). The top 3 are the suspected sources of most problems you may be facing. There are a lot of moving parts involved. All in all learning debugging skills so you can become self-sufficient and solve your own problems is key here.
Want results from more Discord servers?
Add your server