-
Notifications
You must be signed in to change notification settings - Fork 3.1k
loadSessionStateSnapshotIntoStore crashes when currentPageId is undefined #7993
Description
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
- Open a file on tldraw.com
- Ensure the URL has a
?d=deep link parameter - Have a saved
lastSessionStatein the file state - 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 strippedThis 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)