Skip to content

Drag & Dropping Powers without Power Source breaks character sheets #15

@Leonaquilla

Description

@Leonaquilla

Where is the issue happening?

System

Premium Module

Invincible Quickstart

Describe the bug

When you drag and drop a power item onto the actor sheet, _onDropItemCreate runs and successfully creates the item on the actor via:
jsreturn this.actor.createEmbeddedDocuments('Item', itemData);
The power item is stored on the actor with its system.powerSource field set to whatever value it had in its source (a compendium or another actor).

That value is either:
null/undefined — the power was never assigned to a Power Source, OR
A stale ID — it references a Power Source that exists on the original actor but does not exist on the target actor

the actor now owns a power item that points to a Power Source ID that doesn't exist in its own item collection.

After any change to the actor (including the item just being created), Foundry re-renders the sheet by calling _prepareContext → _prepareItems. This is where it dies every single time:
js// Line 269 — crashes on EVERY render from this point on
powers[i.system.powerSource ?? powerSources[0].id].powers.push(i);
The power now lives permanently on the actor with a bad powerSource reference. There is no fallback that survives this — if i.system.powerSource holds a stale ID, the ?? fallback never fires (because the value isn't nullish, it's just wrong), so powers[staleId] returns undefined, and .powers.push(i) throws.
The sheet can no longer open, render, or be edited because every render attempt hits this line and crashes before the HTML is ever produced.

The corrupted power item is persisted to the world's database. Because _prepareItems crashes before the sheet renders, you can't open the sheet to manually fix or delete the item. The actor is effectively bricked for as long as that orphaned power item exists on it.

Reproduction

  1. Drag and drop a power onto a new character sheet
  2. Close and attempt to reopen the character sheet

Expected Behaviour

Sheet opens

Actual Behaviour

Sheet does not open

Logs

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'id')
at InvincibleActorSheet._prepareItems (actor-sheet.mjs:269:56)
at async InvincibleActorSheet._prepareContext (actor-sheet.mjs:129:5)
at async #render (foundry.mjs:27220:21)
at async #try (foundry.mjs:7169:17)

Screenshots

No response

System Info

n/a

Validations

  • Done a clean install of the system.
  • Disabled all modules (unless the issue is on a premium module).
  • Checked that the issue is present in a new world instance (create an empty new world in Foundry using the system).
  • Not a "How To"-question (You can ask questions here: Discussions).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions