LearnNewsExamplesServices
Frontmatter
id19336
titleSharedCanvas renderers keep drawing while their window is hidden
stateClosed
labels
bugaiperformancecore
assigneesneo-opus-vega
createdAtSep 30, 2026, 8:25 PM
updatedAtSep 30, 2026, 11:17 PM
githubUrlhttps://github.com/neomjs/neo/issues/19336
authorneo-opus-vega
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[]
blocking[]
closedAtSep 30, 2026, 11:17 PM

SharedCanvas renderers keep drawing while their window is hidden

Closed v13.2.0/archive-v13-2-0-chunk-23 bugaiperformancecore
neo-opus-vega
neo-opus-vega commented on Sep 30, 2026, 8:25 PM

Context

Grace measured this on the Fleet Manager's Home field (neomjs/neo-agent-institution#360, motion observation, 2026-09-30). Under useSharedWorkers the canvas worker has no requestAnimationFrame (undefined in a SharedWorker), so the renderer's loop runs on setTimeout(1000 / 60), and nothing pauses it while the window is hidden. Measurement 11 in D#18730 (2026-09-21) left the same question open: rAF throttles itself in a hidden document, a worker's timer does not. Unmeasured: Playwright's Chromium never reported the page hidden, so no probe has watched a hidden window's canvas worker yet.

The Problem

An animating Neo.app.SharedCanvas renderer keeps stepping and drawing while nobody can see it, for example in a minimized Fleet Manager or a background portal tab. The engine records the premise itself: "a hidden document throttles its own timers, not a worker's or its messages" (src/worker/HiddenTick.mjs:4).

The Architectural Reality

Read at dev 7ff8467baa:

  • Neo.app.SharedCanvas#pause / #resume (src/app/SharedCanvas.mjs:249, :304) forward to the renderer. Their only callers are the portal hero's deactivate() / activate() (apps/portal/view/home/parts/hero/Container.mjs:52, :44), which pause the hero while its part is out of view. Nothing pauses on the window's visibility.
  • Neo.canvas.Base#pause sets isPaused, canRender honours it, and #resume restarts the loop (src/canvas/Base.mjs:212, :142, :226).
  • Neo.worker.App#onVisibilityChange (src/worker/App.mjs:840) fires the window's app visibilitychange with {hidden, windowId}. Neo.component.MagicMoveText subscribes to it (src/component/MagicMoveText.mjs:224).
  • SharedCanvas hosts: Neo.app.header.Canvas; the portal's hero, footer, timeline and services canvases; the Institution's ObservatoryCanvas and Home canvas.

The Fix

Neo.app.SharedCanvas takes its window's current visibility and subscribes to its app's visibilitychange, after MagicMoveText's precedent: pause while hidden, resume when visible. A window that is already hidden never reports, so the current state is read, not waited for. The subscription follows the host into another window and ends on destroy. A hidden window and a host's own pause() are two separate reasons: the renderer runs only when neither holds, so a portal hero paused out of view stays paused when its window comes back.

Acceptance Criteria

  • AC-1 The app's visibilitychange with hidden: true pauses the host's renderer, and hidden: false resumes it. The subscription follows the host into another window, and a destroyed host no longer listens. Unit arm with the renderer stubbed.
  • AC-2 A host paused for its own reason stays paused across a hide and show: the portal hero, deactivated, then hidden, then shown, is still paused.
  • AC-3 No engine or portal SharedCanvas renderer jumps on its first frame after a resume.
  • AC-4 (post-merge, once the Institution's engine pin includes it) [L4-deferred — operator handoff needed] With the installed Fleet Manager's window minimized, Home's getStats().frames does not advance, and the Observatory's canvas draws no frames. Residual-Owner: neomjs/neo-agent-institution#367.

Contract Ledger

Rows read at PR #19338's head b636b1de6d.

Target Surface Source of Authority Proposed Behavior Fallback Docs Evidence
Neo.app.SharedCanvas#pause / #resume this ticket; the portal hero's activate() / deactivate() are the callers The host's own pause reason (hostPaused). A pause before the canvas is ready holds once it is Nothing is forwarded before isCanvasReady JSDoc unit/app/SharedCanvasVisibility.spec.mjs, host-pause arm
The visibility subscription: SharedCanvas#listenToWindow and #onWindowVisibility Neo.worker.App#onVisibilityChange fires the window app's visibilitychange On construct and on a window move, the host takes the window's current visibility, then follows its reports. It lets go of the old window's app on a move and on destroy An app that never reports leaves the current visibility in force JSDoc the same spec: hide/show, follow/destroy, created-hidden, moved-into-hidden
Neo.worker.HiddenTick#isHidden(windowId) (new) App#onConnect seeds it from document.hidden; every visibilitychange updates it true while the window's last report said hidden false for a window it never heard from JSDoc the spec's hidden-window arms; the unit worker mock answers visible
Renderer forwarding: renderer.pause / resume({windowId}) Neo.canvas.Base#pause / #resume and canRender syncRenderLoop forwards the combined state while the canvas is ready. A canvas that becomes ready while paused starts paused Nothing before ready JSDoc the spec's ready-while-hidden arm

Out of Scope

  • requestAnimationFrame in SharedWorkers, and Electron's background throttling.
  • Renderers hosted outside SharedCanvas, such as the Sparkline under Neo.component.Canvas: the same loop behind a different host.
  • The open presenter and grouping questions of D#18730.

Avoided Traps

  • Pausing from each app's view: every host would repeat the same listener, and the next SharedCanvas would miss it. The engine owns the renderer's lifecycle.
  • One pause flag for both reasons: a visibility resume() would wake a host that paused itself, as the portal hero does while out of view.

Related

D#18730 · neomjs/neo-agent-institution#360

Decision Record impact: none. Structure map: N/A. The change stays in existing engine files (src/app/SharedCanvas.mjs, possibly src/canvas/Base.mjs) and adds no file or folder. Live latest-open sweep: the latest 20 open issues at 2026-09-30T18:25:21Z; no equivalent found. A2A in-flight claim sweep (all read states, last 30): no claim on SharedCanvas or canvas visibility. MC sweep: "shared canvas render loop keeps running while the window is hidden, SharedCanvas pause resume never called, HiddenTick hidden window worker timers", 6 results; D#18730 measurement 11 left the question open, no decision found. Exact search: gh search issues --owner neomjs "canvas pause hidden visibilitychange", 0 results. Own-assignment sweep: 6 open in this repository, none on canvas lifecycle.

Origin Session ID: eee527e0-79de-4edb-b4c2-eb89d3780d56 Retrieval Hint: query_raw_memories("SharedCanvas renderer keeps drawing while the window is hidden visibilitychange pause resume")

tobiu referenced in commit e7d550e - "feat(app): SharedCanvas pauses its renderer while its window is hidden (#19336) (#19338) on Sep 30, 2026, 11:17 PM
tobiu closed this issue on Sep 30, 2026, 11:17 PM