Skip to content

loadSessionStateSnapshotIntoStore crashes when currentPageId is undefined #7993

@MitjaBezensek

Description

@MitjaBezensek

When a session state snapshot without currentPageId is loaded (e.g. via deep links in dotcom), loadSessionStateSnapshotIntoStore passes undefined to store.schema.types.instance.create(), which fails validation:

ValidationError: At instance.currentPageId: Expected string, got undefined

React Router catches this during render, breaking the app.

Steps to reproduce

  1. Open a file on tldraw.com
  2. Ensure the URL has a ?d= deep link parameter
  3. Have a saved lastSessionState in the file state
  4. Refresh the page

Root cause

PR #7917 introduced code in TlaEditor.tsx that strips currentPageId from the session state when a deep link is present:

const { pageStates: _, currentPageId: _cpid, ...preferencesOnly } = sessionState
editor.loadSnapshot({ session: preferencesOnly }, { forceOverwriteSessionState: true })

In loadSessionStateSnapshotIntoStore, line 241 unconditionally sets:

currentPageId: res.currentPageId, // undefined when stripped

This overrides the ...preserved spread above it, and the instance validator rejects undefined.

Fix

loadSessionStateSnapshotIntoStore should fall back to the preserved (existing) value when currentPageId is not in the snapshot:

currentPageId: res.currentPageId ?? preserved?.currentPageId,

This is consistent with how all the other fields (isDebugMode, isFocusMode, etc.) use ?? fallbacks, and currentPageId is already typed as optional in TLSessionStateSnapshot.

Relevant files

  • packages/editor/src/lib/config/TLSessionStateSnapshot.ts (line 241)
  • apps/dotcom/client/src/tla/components/TlaEditor/TlaEditor.tsx (lines 138-142)

Metadata

Metadata

Assignees

Labels

dotcomRelated to tldraw.comsdkAffects the tldraw sdk

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions