Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Aug 18, 2025

https://www.loom.com/share/bf2e0a05c2b54f0fba6528eb02a489aa

Summary by CodeRabbit

  • New Features

    • Canvas can now be rendered in the sidebar, not just the main page.
    • More reliable canvas insertion reduces duplicate or missed renders.
  • Bug Fixes

    • Prevents non-canvas content from being hidden; hiding now applies only within canvas areas.
    • Improved cleanup when canvases are removed.
  • Style

    • Updated selectors for consistent canvas styling across page and sidebar.
    • Ensures SVG elements within the canvas are styled uniformly.

…d sidebar contexts. Update utility functions to support sidebar canvas rendering.
@linear
Copy link

linear bot commented Aug 18, 2025

@supabase
Copy link

supabase bot commented Aug 18, 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 18, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 18, 2025

📝 Walkthrough

Walkthrough

Refactors Tldraw canvas rendering to a generalized helper that patches target DOM regions using a shared data-attribute. Adds sidebar-specific rendering and detection. Updates initialization to render canvases in both main page and sidebar. Adjusts CSS to use a shared attribute and class selectors, exporting the attribute constant.

Changes

Cohort / File(s) Summary
Canvas rendering refactor and sidebar support
apps/roam/src/components/canvas/Tldraw.tsx, apps/roam/src/utils/initializeObserversAndListeners.ts, apps/roam/src/utils/isCanvasPage.ts
Introduces renderTldrawCanvasHelper for idempotent DOM patching; adds renderTldrawCanvasInSidebar; updates observers to handle main and sidebar canvases separately; adds isSidebarCanvas utility mirroring current-page detection for the sidebar.
Styling and selectors update
apps/roam/src/components/canvas/tldrawStyles.ts
Exports TLDRAW_DATA_ATTRIBUTE; switches CSS to use the shared data-attribute for targeted hiding in main and sidebar; changes container selector from ID to class; updates commented references.

Sequence Diagram(s)

sequenceDiagram
  participant Observer as PageTitleObserver
  participant Utils as isCurrentPageCanvas / isSidebarCanvas
  participant Tldraw as Tldraw module
  participant Helper as renderTldrawCanvasHelper
  participant DOM as DOM
  participant Ctx as ExtensionApiContextProvider

  Observer->>Utils: Check main-page canvas
  alt Main-page is canvas
    Observer->>Tldraw: renderTldrawCanvas({ title, onloadArgs })
    Tldraw->>Helper: renderTldrawCanvasHelper(article selector, dims)
    Helper->>DOM: Patch parent (set data-attr), wrap children
    Helper->>Ctx: Render Tldraw with renderWithUnmount
  end

  Observer->>Utils: Check sidebar canvas
  alt Sidebar is canvas
    Observer->>Tldraw: renderTldrawCanvasInSidebar({ title, onloadArgs })
    Tldraw->>Helper: renderTldrawCanvasHelper(sidebar selector, dims)
    Helper->>DOM: Patch parent (set data-attr), wrap children
    Helper->>Ctx: Render Tldraw with renderWithUnmount
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 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: 3

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

2-2: Consider using a data- attribute for HTML validity

Custom non–data-* attributes are allowed in HTML5 and will work with attribute selectors, but using a data- attribute (e.g., data-dg-tldraw-canvas-wrapper) better communicates intent and avoids potential tooling or validator complaints. This would require updating both the constant and the selectors where it’s used.

apps/roam/src/utils/initializeObserversAndListeners.ts (1)

80-82: Good: separate branches for article vs sidebar canvases

The ordering avoids double-rendering. One note: both renderTldrawCanvas* functions return cleanup functions, but they’re not captured/used here. If renderWithUnmount internally handles DOM removal cleanly, this may be fine; otherwise, it could leak the wrapper or leave the attribute set. I’ve suggested a JS fix that scopes the patch to the specific H1’s container and removes the wrapper on cleanup.

Would you like me to wire the returned cleanup functions into a lifecycle that unsets the attribute and removes the wrapper on page/sidebar unmount?

📜 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 8ac1ce1 and 0e2ab12.

📒 Files selected for processing (4)
  • apps/roam/src/components/canvas/Tldraw.tsx (3 hunks)
  • apps/roam/src/components/canvas/tldrawStyles.ts (3 hunks)
  • apps/roam/src/utils/initializeObserversAndListeners.ts (2 hunks)
  • apps/roam/src/utils/isCanvasPage.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/roam/src/utils/initializeObserversAndListeners.ts (2)
apps/roam/src/utils/isCanvasPage.ts (2)
  • isCurrentPageCanvas (11-19)
  • isSidebarCanvas (21-29)
apps/roam/src/components/canvas/Tldraw.tsx (2)
  • renderTldrawCanvas (893-907)
  • renderTldrawCanvasInSidebar (909-923)
apps/roam/src/components/canvas/Tldraw.tsx (1)
apps/roam/src/components/canvas/tldrawStyles.ts (1)
  • TLDRAW_DATA_ATTRIBUTE (2-2)
🔇 Additional comments (6)
apps/roam/src/utils/isCanvasPage.ts (1)

21-29: Sidebar detection utility looks good and mirrors current-page logic

The predicate is simple, consistent with isCurrentPageCanvas, and reuses isCanvasPage as a gate. No issues spotted.

apps/roam/src/components/canvas/tldrawStyles.ts (1)

22-24: Selector update from id to class is correct

Matches the container’s updated className. This will ensure the “overflow visible” fix applies.

apps/roam/src/utils/initializeObserversAndListeners.ts (2)

9-12: New imports align with the split rendering paths

The addition of renderTldrawCanvasInSidebar pairs with the new sidebar detection logic.


18-18: Importing both canvas predicates is appropriate

This supports routing to the correct render path based on context. No issues.

apps/roam/src/components/canvas/Tldraw.tsx (2)

85-85: Importing the shared attribute constant is the right move

Centralizing the attribute value avoids drift between CSS and JS.


471-471: Container switched to class-based selector; matches CSS change

The class roamjs-tldraw-canvas-container aligns with the updated CSS. No concerns.

@mdroidian mdroidian merged commit e5c79f1 into main Aug 18, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Aug 18, 2025
@mdroidian mdroidian deleted the eng-741-allow-canvas-to-be-opened-in-sidebar branch August 18, 2025 06:45
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