Skip to content

fix(dockview): correct pop-out restore double-offset (wrong-monitor drift)#176

Open
awaisali88 wants to merge 1 commit into
developfrom
fix/dockview-popout-restore-offset
Open

fix(dockview): correct pop-out restore double-offset (wrong-monitor drift)#176
awaisali88 wants to merge 1 commit into
developfrom
fix/dockview-popout-restore-offset

Conversation

@awaisali88

Copy link
Copy Markdown
Contributor

What & why

Restored pop-out windows drift onto the wrong monitor today. dockview's toJSON() saves each pop-out's position as absolute screen coordinates, but fromJSONaddPopoutGroup re-opens at window.screenX + position.left — re-adding the main window's screen offset to coordinates that are already absolute (dockview-core 6.6.1, dockview-core.js:14580-14581). Whenever the main window isn't at the screen origin (any multi-monitor setup), the pop-out lands offset by the main window's position.

This is a latent bug independent of the multi-window-restore feature; it ships first as its own fix (Phase 0 of the feature design spec, docs/superpowers/specs/2026-06-14-multi-window-restore-design.md).

The fix

session.loadLayout now pre-subtracts the main window's current screenX/screenY from each saved pop-out position before fromJSON, via a new pure helper correctPopoutRestoreOffset (src/modules/dockview/popoutOffset.ts). dockview's re-addition then cancels and the window lands at its true saved absolute coordinates. No-op when there are no pop-outs or the main window is at (0,0).

Couples to dockview's internal offset math — flagged for re-verify on dockview bumps (CLAUDE.md library-gotcha rule).

Verification

Stage 1 (automated): the wrong-monitor manifestation requires real multiple monitors + pop-ups allowed for the origin, which isn't headless-reproducible — so there is no Playwright run embedded for this PR. The coordinate-correction logic is instead covered by 5 unit tests (tests/unit/modules/dockview/popoutOffset.spec.ts): offset subtraction, the round-trip invariant (corrected + origin == saved absolute), no-mutation of the persisted blob, null-position passthrough, and the no-op short-circuits.

Static gauntlet: lint ✓ · type-check (cache-free) ✓ · test 715/715 ✓ · spell ✓ · build ✓.

Stage 2 — human review (multi-monitor)

Tick each box; merge only when all are checked. To drive: pnpm dev on a multi-monitor machine, allow pop-ups for localhost.

  • Pop a panel out, drag it onto a second monitor, Save Layout, reload, allow the pop-up — it reopens on the same monitor at the same spot (not drifted onto the primary).
  • With the main window on a non-primary monitor, repeat — the pop-out still lands where it was saved.
  • A layout with no pop-outs loads unchanged (no regression to the normal restore path).
  • Pop-out theme/tokens still seed correctly on restore (no flash of default theme).
  • Ready to merge.

Specifically scrutinize: that the correction reads the current main-window origin at restore time (robust to the main window having moved between sessions), and that the normal no-pop-out restore path is untouched.

🤖 Generated with Claude Code

…rift)

dockview's toJSON() serializes each pop-out group's position as ABSOLUTE screen
coords (the pop-out window's screenX/screenY), but on restore fromJSON →
addPopoutGroup re-opens the window at `window.screenX + position.left`, adding
the MAIN window's screen offset to coords that are already absolute
(dockview-core 6.6.1). On a multi-monitor setup — or any time the main window
isn't at the screen origin — the restored pop-out drifts by the main window's
offset and can land on the wrong monitor.

`loadLayout` now pre-subtracts the main window's current screen origin from each
saved pop-out position (new pure helper `correctPopoutRestoreOffset`) before
fromJSON, so dockview's re-addition cancels and the window lands at its true
saved absolute coordinates. No-op when there are no pop-outs or the main window
is at (0,0). Unit-tested (offset math, round-trip invariant, no-mutation,
null-position passthrough, no-op short-circuits).

Compensates for dockview internal offset math — re-verify on dockview bumps.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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