Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Oct 16, 2025

createTlStore doesn't apply migrations

So users were getting errors related to missing size and fontFamily

At shape(type = Uht8c3nBh).props.size: Expected "s" or "m" or "l" or "xl", got undefined

I think this is fixed/changed in 2.4.0 with a snapshot prop tldraw/tldraw#4233

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and recovery during store initialization and snapshot loading, with clearer UI error/loading states and telemetry.
    • Centralized reporting to reduce duplicate notifications and include snapshot context when safe.
    • Loading now occurs after initial store creation, aborting gracefully on failure to prevent partial or corrupted state.

@linear
Copy link

linear bot commented Oct 16, 2025

@supabase
Copy link

supabase bot commented Oct 16, 2025

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

Copy link
Contributor Author

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

@coderabbitai full review

@mdroidian
Copy link
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

📝 Walkthrough

Walkthrough

Deferred loading of an initial snapshot until after TLStore creation and centralized store error handling: added handleStoreError to log, update UI state, emit telemetry, and send contextual error emails; removed initialData from createTLStore and replaced duplicated error paths with shared handling and conditional snapshot inclusion in emails.

Changes

Cohort / File(s) Change Summary
Store init & error handling refactor
apps/roam/src/components/canvas/useRoamStore.ts
Removed initialData from createTLStore; load snapshot after successful store creation via loadSnapshot(_store, initialSnapshot); introduced handleStoreError to centralize logging, UI state updates, telemetry, and contextual email sending (includes snapshotSize check to conditionally attach snapshot); updated catch blocks to call handleStoreError for creation and migration failures.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Hook as useRoamStore Hook
    participant Store as TLStore
    participant Handler as handleStoreError
    participant Email as Email Service

    Caller->>Hook: initialize store

    rect rgb(210,230,255)
    Note over Hook,Store: Create store (no initialData)
    Hook->>Store: createTLStore()
    alt success
        Store-->>Hook: store instance
    else failure
        Store-->>Hook: creation error
        Hook->>Handler: handleStoreError("Failed to create TLStore", error, ctx)
        Handler->>Email: send contextual email
        Handler-->>Hook: rethrow/error state
    end
    end

    rect rgb(255,245,200)
    Note over Hook,Store: Post-creation snapshot loading
    alt initialSnapshot exists
        Hook->>Store: loadSnapshot(_store, initialSnapshot)
        alt success
            Store-->>Hook: snapshot loaded
        else migration error
            Store-->>Hook: migration error
            Hook->>Handler: handleStoreError("Failed to migrate snapshot", error, { snapshotSize })
            Handler->>Email: send contextual email (attach snapshot if small)
            Handler-->>Hook: rethrow/error state
        end
    else no snapshot
        Hook-->>Hook: continue without loading
    end
    end

    Hook->>Caller: return store or error state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "ENG-942 Canvas migration bug" is directly related to the main change in the pull request. The changeset addresses a documented issue where createTLStore doesn't apply migrations, resulting in user-facing errors due to missing properties like size and fontFamily on shapes. The changes implement centralized error handling and post-creation snapshot loading to fix this migration bug. The title is concise, specific, and clearly identifies the primary objective of the fix—addressing a canvas-related migration issue. A teammate scanning the git history would immediately understand this PR addresses a bug fix for canvas migrations.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffc313a and b6a1426.

📒 Files selected for processing (1)
  • apps/roam/src/components/canvas/useRoamStore.ts (1 hunks)

…or handler for store creation and snapshot migration failures. This improves error logging and email notifications for better debugging and user support.
@mdroidian
Copy link
Contributor Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 16, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
apps/roam/src/components/canvas/useRoamStore.ts (1)

158-158: Consider extracting the size threshold as a named constant.

The 10000 byte threshold for including snapshots in error emails is hardcoded. Extracting it as a named constant (e.g., MAX_SNAPSHOT_SIZE_FOR_EMAIL) would improve maintainability.

Example:

const MAX_SNAPSHOT_SIZE_FOR_EMAIL = 10000; // 10KB

Then reference it on line 158:

-          ...(snapshotSize < 10000 ? { initialSnapshot } : {}),
+          ...(snapshotSize < MAX_SNAPSHOT_SIZE_FOR_EMAIL ? { initialSnapshot } : {}),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffc313a and 8bf49e7.

📒 Files selected for processing (1)
  • apps/roam/src/components/canvas/useRoamStore.ts (1 hunks)
🔇 Additional comments (3)
apps/roam/src/components/canvas/useRoamStore.ts (3)

138-161: Excellent centralized error handling—previous review concerns fully addressed.

The handleStoreError helper correctly consolidates logging, state updates (setError, setLoading), telemetry, and email notifications. This addresses the previous review comment's concerns:

  1. ✓ Error state is now properly set (line 146)
  2. ✓ No duplicate emails—callers return null instead of re-throwing
  3. ✓ Consistent error handling across both creation and migration failures

The conditional snapshot inclusion (line 158) based on size is a smart optimization to prevent massive emails while still capturing snapshotSize for all errors.


166-178: Correct fix for the migration bug.

Removing initialData from createTLStore is the key change that allows tldraw to apply migrations properly. The error handling correctly routes through handleStoreError, ensuring state consistency.


180-190: Post-creation snapshot loading completes the migration fix.

Loading the snapshot after store creation (rather than during instantiation) allows loadSnapshot to apply the necessary migrations. The error handling is correct: it calls handleStoreError and returns null without re-throwing, preventing duplicate notifications.

@mdroidian mdroidian merged commit 9204ce9 into main Oct 16, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Oct 16, 2025
@mdroidian mdroidian deleted the eng-942-canvas-migration-bug branch October 16, 2025 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants