Skip to content

feat(sheets): remember last active sheet on reopen#496

Open
the-narwhal wants to merge 4638 commits into
ProtonMail:mainfrom
the-narwhal:remember-last-active-sheet
Open

feat(sheets): remember last active sheet on reopen#496
the-narwhal wants to merge 4638 commits into
ProtonMail:mainfrom
the-narwhal:remember-last-active-sheet

Conversation

@the-narwhal
Copy link
Copy Markdown

Note on Testing

This PR was implemented via static analysis of the codebase only. The editor runs inside an iframe with a full Proton Drive/RTS backend, so end-to-end verification wasn't possible in this context. The change is submitted as a complete, ready-to-review implementation for Proton to merge as-is, iterate on, or use as a reference. Unit-level logic is straightforward and self-contained; the main thing that warrants a real integration smoke test before shipping is confirming documentId is stable and populated by the time initializeEditor fires for the sheet case.


Remember Last Active Sheet on Reopen

Closes the community-requested UX gap where opening a multi-worksheet spreadsheet always landed on tab 1, regardless of where the user left off.

Problem

handleInitialLoad in useYjsState unconditionally called onChangeActiveSheet(firstSheetId) after receiving the initial RTS sync. There was no persistence of the active sheet between sessions.

Solution

Two small additions to useYjsState in state.ts:

On open: restore saved sheet
handleInitialLoad now checks localStorage before defaulting to sheet 1. If a saved sheet ID is found and the sheet still exists in the document, it is activated instead. If the saved sheet has since been deleted, or this is the first time the document is opened, it falls back to sheet 1 exactly as before.

On tab switch: persist active sheet
A new saveActiveSheetToStorage effect writes the current activeSheetId to localStorage whenever it changes, gated on receivedEverythingFromRTS to avoid persisting the library's pre-load default value.

Storage key design
Keys are scoped to both documentId and userName so that collaborators on the same shared spreadsheet each independently remember their own last position:

proton-sheets-active-sheet:{documentId}:{userName}

Files Changed

  • state.ts — all logic lives here: getActiveSheetStorageKey helper, documentId added to YjsStateDependencies (which automatically propagates to ProtonSheetsStateDependencies via the existing type spread), modified handleInitialLoad, new saveActiveSheetToStorage effect
  • Spreadsheet.tsxdocumentId: string added to SpreadsheetProps, threaded into useProtonSheetsState
  • App.tsxdocumentId={editorConfig.current.documentId} passed to <Spreadsheet>, mirroring the existing pattern already used for <Editor>

What Was Not Changed

  • No changes to the Yjs document content or RTS sync; this is purely client-side localStorage
  • No changes to sheet switching UX or collaborator cursor following
  • Fallback to sheet 1 is fully preserved for first-open and deleted-sheet cases
  • Read-only and revision modes are unaffected

Integration Smoke Test Recommended

Before merging, confirm:

  1. Open a spreadsheet, switch to a non-first sheet, close and reopen. Should land on that sheet.
  2. Open the same spreadsheet as a second user. Their position should be tracked independently.
  3. Switch to a sheet, delete it, then reopen. Should fall back to sheet 1 without errors.
  4. Open a brand new spreadsheet for the first time. Should open on sheet 1 as before.

Raphael Rychetsky and others added 30 commits April 21, 2026 09:15
Prevent concurrent referral spotlight feature PUTs

See merge request web/clients!24282
VPNPLG-58: Add payload and telemetry when forking the session

See merge request web/clients!24135
fix: fix icon alignment in cancellation flow

See merge request web/clients!24315
Add offer card UI components

See merge request web/clients!24302
added temporary need content and config

See merge request web/clients!24307
feat: workspace premium cancelation flow

See merge request web/clients!24319
Add news subscription for Meet

See merge request web/clients!24209
use the same setting menu for extension as for web

See merge request web/clients!24241
INWEB-867: Add common setup for Slack API in the CI

See merge request web/clients!24271
Add new permissions modals and stop requesting permissions automatically

See merge request web/clients!24248
DRVWEB: Search blobs encryption/decryption

See merge request web/clients!23888
[IDTEAM-5613] Add telemetry for sharing

See merge request web/clients!24221
Limit sharing settings visibility only to admins on parent share

See merge request web/clients!24326
[DRVWEB-4974] Album listing sdk

See merge request web/clients!23946
Enable telemetry for Meet

See merge request web/clients!24331
MargeBot and others added 24 commits April 24, 2026 09:01
Idteam 5873 fix safari too small popup

See merge request web/clients!24390
Add `justify-start-when-stacked` table helper

See merge request web/clients!24428
Prevent missing navigator.mediaDevices to throw

See merge request web/clients!24429
Update category counts when labelling a message from a conversation

See merge request web/clients!24325
Update openSubscriptionModal usage

See merge request web/clients!24107
Fix a bug storing feature flags in cookie

See merge request web/clients!24454
[DRVWEB-4967] delete legacy drive view

See merge request web/clients!24263
NOISSUE: Adapt telemetry for tv flow

See merge request web/clients!24405
Defer update prompt if user is in meeting

See merge request web/clients!24450
Mail BYOE: hide lock icons in sent messages when `X-Pm-Byoe` header is present

See merge request web/clients!24000
PostQuantumOptInModal: prompt for auth before committing the opt-in

See merge request web/clients!24457
Add LoginLink member creation mode

See merge request web/clients!24448
When a spreadsheet with ultiple worksheets is opened, the editor now
restores the user's last-visited sheet instead of always defaulting to
the first tab.

Implementation:
- On every active-sheet change (after initial RTS sync), persist the
  sheet ID to localStorage under a key scoped to both the document ID
  and the user, so collaborators each retain their own position.
- On initial load, read that key and activate the saved sheet if it
  still exists in the document; otherwise fall back to sheet 1 as
  before (covers first-open and deleted-sheet cases).
- Thread `documentId` from App → Spreadsheet → useProtonSheetsState →
  useYjsState to provide a stable per-document storage key.
@the-narwhal the-narwhal marked this pull request as ready for review April 26, 2026 17:51
@mmso mmso force-pushed the main branch 5 times, most recently from 115579e to b6fd253 Compare June 3, 2026 16:16
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.