Skip to content

fix: guard null PIXI stage and detach spiderhog listener on teardown - #35

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-spiderhog-null-stage-crash
Draft

fix: guard null PIXI stage and detach spiderhog listener on teardown#35
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/fix-spiderhog-null-stage-crash

Conversation

@posthog

@posthog posthog Bot commented Jul 15, 2026

Copy link
Copy Markdown

What

Fixes a rare uncaught TypeError: Cannot read properties of null (reading 'addChild') in the toolbar-embedded hedgehog mode.

The spiderhog skin registers a global pointerdown listener that spawns a SpiderWebActor on every click. HedgeHogMode.destroy() tore down the PIXI app (app.destroy()) without unloading its elements, so that listener stayed attached after teardown. A later click then spawned onto a destroyed app and dereferenced a null app.stage in Actor.loadSpriteFrames. The same null-stage window exists briefly before app.init() resolves.

Changes

  • destroy() now calls beforeUnload() on every element before destroying the app, so ability-owned listeners — notably the spiderhog pointerdown — detach and can't fire post-teardown.
  • Actor.loadSpriteFrames, SpiderWebActor.spawn, and the removeChild sites bail when the stage is absent, so any stray spawn during the init/teardown gap no-ops instead of crashing.
  • Bumps the package to 0.0.54 (auto-published on merge to main).

Why

Genuine uncaught crash in production-served toolbar code. Impact is small — it's an opt-in cosmetic easter egg and needs a narrow pointerdown timing race — but the fix is cheap and self-contained.

Testing

  • pnpm lint and pnpm build pass.
  • Added test/spider-web-actor.test.ts covering the spawn null-stage guard.

Note: after this publishes, bump @posthog/hedgehog-mode in PostHog/posthog (frontend/package.json) to ^0.0.54 to pull the fix into the toolbar.


Created with PostHog Code from an inbox report.

The spiderhog skin registers a global pointerdown listener that spawns a web on
every click. HedgeHogMode.destroy() tore down the PIXI app without unloading its
elements, so that listener survived teardown and a later click spawned onto a
destroyed app — dereferencing a null app.stage in Actor.loadSpriteFrames. The
same null stage exists briefly before app.init() resolves.

- destroy() now runs beforeUnload() on every element before destroying the app,
  so ability-owned listeners (the spiderhog pointerdown) detach.
- loadSpriteFrames, SpiderWebActor.spawn, and the removeChild sites bail when
  the stage is absent, so a stray spawn during the init/teardown gap no-ops
  instead of crashing.

Bumps the package to 0.0.54.

Generated-By: PostHog Code
Task-Id: f2e7dabb-cb62-4d61-b4b0-32c1809252cb
@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hedgehog-mode Ready Ready Preview Jul 15, 2026 3:40am
hogwars Error Error Jul 15, 2026 3:40am

Request Review

// Unload every element while the stage is still alive so listener-owning
// abilities detach — notably the spiderhog skin's global pointerdown, which
// would otherwise survive teardown and spawn a web onto a destroyed app.
for (const element of [...this.elements]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should cancel element-owned timers and tweens during teardown, or make beforeUnload() idempotent. released webs and flames retain callbacks that later call removeElement(). after this sweep has already cleaned them up, those callbacks repeat cleanup, decrement the global spawn counters twice, and may destroy PIXI resources twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant