Skip to content

fix(window-state): eliminate "main" window label to fix stale geometry restore#906

Merged
rgbkrk merged 3 commits intomainfrom
quill/fix-tiny-window-restore
Mar 17, 2026
Merged

fix(window-state): eliminate "main" window label to fix stale geometry restore#906
rgbkrk merged 3 commits intomainfrom
quill/fix-tiny-window-restore

Conversation

@rgbkrk
Copy link
Copy Markdown
Member

@rgbkrk rgbkrk commented Mar 17, 2026

Summary

  • Root cause: tauri-plugin-window-state persists window geometry by label. The app reused Tauri's auto-created "main" window as the first notebook, but this generic label accumulated stale geometry — if it was ever saved at a tiny size, every subsequent launch restored that tiny window.
  • Fix: All notebook windows (including the first) are now created explicitly with proper "notebook-{hash}" labels through the same code path used by create_notebook_window_for_daemon. No more "main" special case.
  • Empties the windows array in tauri.conf.json (no auto-created default window)
  • Adds "main" to the window-state plugin denylist as a safety net for users upgrading from older versions
  • Removes "main" special cases from: window close handler, file association (Finder double-click), macOS dock reopen, and session restore
  • Session restore now uses the first entry rather than finding label == "main"
  • Adds find_empty_window_label() to generically reuse any untitled window for file association

Closes #849

Test plan

  • Launch app fresh (no session) — opens with proper notebook-* label
  • Open a saved notebook — gets deterministic notebook-{hash} label
  • Close and relaunch — window geometry restores correctly
  • Delete ~/Library/Application Support/io.nteract.runt-nightly/.window-state.json, resize window tiny, quit, relaunch — does NOT restore tiny size (fresh label)
  • File association (double-click .ipynb in Finder) — opens in empty window or new window
  • macOS dock click with no windows — creates new notebook
  • Session restore (Cmd+Q and relaunch) — all windows restore
  • Upgrade from old version with "main" in session.json — restores correctly with new label

…y restore

The tauri-plugin-window-state plugin persists window geometry by label.
The app reused Tauri's auto-created "main" window as the first notebook,
but this generic label accumulated stale geometry state — if it was ever
saved at a tiny size, every subsequent launch restored that tiny window.

All notebook windows (including the first) are now created explicitly
with proper "notebook-{hash}" labels through the same code path used by
create_notebook_window_for_daemon. This gives each notebook a
deterministic, content-based label for geometry persistence.

- Empty the windows array in tauri.conf.json (no auto-created window)
- Create first notebook window in setup with proper label
- Add "main" to window-state denylist (safety net for upgrades)
- Remove "main" special cases from close handler, file association,
  dock reopen, and session restore
- Session restore uses first entry instead of finding label=="main"
- Add find_empty_window_label() for generic empty-window reuse

Closes #849
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes stale window-geometry restores caused by reusing Tauri’s auto-created "main" window label by ensuring all notebook windows are explicitly created with deterministic "notebook-*" labels, and adding safeguards for users upgrading from older sessions.

Changes:

  • Removes the default auto-created Tauri window ("windows": []) and creates the first notebook window explicitly with a "notebook-*" label.
  • Adds "main" to the tauri-plugin-window-state denylist and removes "main"-specific handling across startup/session restore and window lifecycle paths.
  • Updates session label behavior/tests to no longer treat "main" as a special passthrough label.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/notebook/tauri.conf.json Removes auto-created default window to avoid the "main" label being used.
crates/notebook/src/session.rs Removes "main" special-casing in label logic and updates tests accordingly.
crates/notebook/src/lib.rs Creates the first notebook window explicitly with a "notebook-*" label; updates session restore and file-association behavior to be label-agnostic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread crates/notebook/src/lib.rs Outdated
Comment on lines +3357 to +3358
// Use the first session window (was the primary window at save time).
if let Some(first_session) = session.windows.first() {
Comment thread crates/notebook/src/lib.rs Outdated
.filter(|w| w.label != "main")
.cloned()
.collect()
session.windows.iter().skip(1).cloned().collect()
rgbkrk added 2 commits March 16, 2026 20:41
Address review feedback: HashMap iteration order is nondeterministic,
so session.windows.first() and skip(1) were unreliable for identifying
the primary window.

- Sort windows by label during save for deterministic ordering
- Add primary_label field to SessionState (skip_serializing_if None
  for backward compat with old session files)
- Use primary_label to find the primary window during restore,
  falling back to first entry for old sessions
- Filter additional session windows by primary_label instead of skip(1)
Instead of distinguishing a "primary" window (created in setup) from
"additional" windows (deferred to after daemon ready), all session
windows are now created immediately in the synchronous setup callback.
Each shows a loading UI until the daemon is available, then all are
synced in a single loop.

This eliminates the need for primary_label, sorted session ordering,
and the first-vs-additional window distinction. All notebook windows
are treated equally — no special cases.
@rgbkrk rgbkrk marked this pull request as ready for review March 17, 2026 04:24
@rgbkrk rgbkrk merged commit 97b0422 into main Mar 17, 2026
12 of 14 checks passed
@rgbkrk rgbkrk deleted the quill/fix-tiny-window-restore branch March 17, 2026 04:24
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.

bug: opening notebook with Untitled session in view leaves things in a torn state

2 participants