Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Aug 27, 2025

  • Added lastActions state to DiscourseContextType for tracking recent changes.
  • Implemented a mechanism to push new actions to lastActions on app change events, maintaining a maximum of 10 entries.
  • Updated error handling to include lastActions context for better debugging.

Summary by CodeRabbit

  • Bug Fixes

    • Improved canvas stability by capturing recent user actions and incorporating them into error handling, making issues easier to detect and reducing ambiguous failures.
  • Chores

    • Added background tracking of the last 10 canvas actions to support faster troubleshooting and support diagnostics.
    • Initialized shared context to include recent action history for consistent behavior across the canvas experience.
    • No changes to UI or workflows; this update operates behind the scenes to enhance reliability and support.

- Added lastActions state to DiscourseContextType for tracking recent changes.
- Implemented a mechanism to push new actions to lastActions on app change events, maintaining a maximum of 10 entries.
- Updated error handling to include lastActions context for better debugging.
@linear
Copy link

linear bot commented Aug 27, 2025

@supabase
Copy link

supabase bot commented Aug 27, 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 ↗︎.

@mdroidian
Copy link
Contributor Author

@CodeRabbit full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 27, 2025

📝 Walkthrough

Walkthrough

Adds action history tracking to the Tldraw canvas by extending the discourse context with lastActions, initializing and persisting it via a ref, subscribing to Tldraw change events on mount to append capped history (10 items), and including lastActions in the error context. Public types and exports are updated accordingly.

Changes

Cohort / File(s) Summary
Canvas history tracking and context extension
apps/roam/src/components/canvas/Tldraw.tsx
- Introduces HistoryEntry and TLRecord usage for action history
- Extends DiscourseContextType with lastActions: HistoryEntry[]
- Initializes discourseContext.lastActions as [] and mirrors via lastActionsRef
- Subscribes onMount to Tldraw change events, pushes entries, caps at 10
- Adds lastActions to Tldraw error reporting context

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant TldrawCanvas
  participant TldrawApp as TLDraw App
  participant History as lastActionsRef / discourseContext.lastActions
  participant ErrorCtx as Error Context

  User->>TldrawCanvas: Mount component
  TldrawCanvas->>TLDraw App: Initialize & subscribe to change events
  note right of TLDraw App: onChange(handler)

  TLDraw App-->>TldrawCanvas: changeEvent(entry)
  TldrawCanvas->>History: Append entry
  TldrawCanvas->>History: Trim to last 10 items

  rect rgba(230,245,255,0.5)
    note over TldrawCanvas,ErrorCtx: Error reporting
    TldrawCanvas->>ErrorCtx: Provide { lastActions, ... }
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 4

🧹 Nitpick comments (1)
apps/roam/src/components/canvas/Tldraw.tsx (1)

91-92: Use type-only imports to avoid bundling runtime code from tldraw packages

These are types; importing them as values can bloat the bundle.

-import { HistoryEntry } from "@tldraw/store";
-import { TLRecord } from "@tldraw/tlschema";
+import type { HistoryEntry } from "@tldraw/store";
+import type { TLRecord } from "@tldraw/tlschema";
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 68d9e53 and 391fcb2.

📒 Files selected for processing (1)
  • apps/roam/src/components/canvas/Tldraw.tsx (5 hunks)
🔇 Additional comments (1)
apps/roam/src/components/canvas/Tldraw.tsx (1)

611-616: Extract, Sanitize, and Cap Per-Canvas History with Proper Cleanup

  • Move the app.on("change", …) subscription into a useEffect that runs once after mount (and whenever the app or title changes) to avoid re-attaching handlers on every render.
  • Capture the unsubscribe function returned by app.on and invoke it in the effect’s cleanup callback to prevent orphaned listeners on remount.
  • Sanitize each entry via redactHistoryEntryForEmail before adding it to the buffer to strip PII.
  • Store the capped history (max 10 entries) in discourseContext.lastActionsByCanvas[title], isolating histories per canvas.

Suggested refactor in apps/roam/src/components/canvas/Tldraw.tsx around lines 611–616:

-              app.on("change", (entry) => {
-                lastActionsRef.current.push(entry);
-                if (lastActionsRef.current.length > 10)
-                  lastActionsRef.current.shift();
-              });
+              useEffect(() => {
+                const offChange = app.on("change", (entry) => {
+                  const safeEntry = redactHistoryEntryForEmail(entry);
+                  const buf = lastActionsRef.current;
+                  buf.push(safeEntry);
+                  while (buf.length > 10) buf.shift();
+                  discourseContext.lastActionsByCanvas[title] = buf;
+                });
+
+                return () => {
+                  offChange();
+                };
+              }, [app, title]);

If your version of tldraw’s app.on does not return an unsubscribe function, you’ll need to bind the listener in this effect and call app.off("change", handler) (or the equivalent) in the cleanup.

@mdroidian mdroidian merged commit 32df04f into main Aug 27, 2025
5 checks passed
@mdroidian mdroidian deleted the eng-747-store-last-10-tldraw-actions-include-in-bug-report branch August 27, 2025 07:22
@github-project-automation github-project-automation bot moved this to Done in General Aug 27, 2025
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