Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Aug 27, 2025

We were using attrs on the child block, but these were being created after render, so not being hidden.

Summary by CodeRabbit

  • Bug Fixes

    • Correctly hides Roam blocks when a canvas is present by applying visibility rules to the parent container, fixing inconsistent hiding in the main page and sidebar.
    • Reliably marks the canvas root container to ensure consistent show/hide behavior and reduce layout flicker.
  • Chores

    • Removed unused insertion logic and debug logging.

…oot element and updating CSS selectors for block visibility. Removed commented-out code for cleaner implementation.
@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 a data attribute to the root container during canvas wrapper injection in Tldraw.tsx. Updates CSS selectors in tldrawStyles.ts to check the attribute on ancestor containers (.roam-article, .rm-sidebar-outline) instead of child elements. Removes unused console logging and a redundant insertBefore call. No public API changes.

Changes

Cohort / File(s) Summary
Canvas wrapper injection marker
apps/roam/src/components/canvas/Tldraw.tsx
Sets TLDRAW_DATA_ATTRIBUTE="true" on the root element when injecting the canvas wrapper; removes unused console.log and a prior insertBefore attempt; append-based injection and unmounting unchanged.
Style gating via ancestor attribute
apps/roam/src/components/canvas/tldrawStyles.ts
Updates two selectors to gate visibility based on the attribute on ancestor containers: from .rm-block-children[attribute] to .roam-article[attribute] .rm-block-children and .rm-sidebar-outline[attribute] .rm-block-children. No other style changes.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Tldraw as Tldraw Component
  participant DOM as Root Element
  participant CSS as CSS Selectors

  User->>Tldraw: Mount component
  Tldraw->>DOM: Inject canvas wrapper
  Tldraw->>DOM: Set data attribute (TLDRAW_DATA_ATTRIBUTE="true")
  CSS-->>DOM: Match ancestor-based selectors
  CSS-->>User: Hide .rm-block-children under marked containers

  User->>Tldraw: Unmount component
  Tldraw->>DOM: Remove wrapper (attribute handling unchanged)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

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

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

933-945: Align gating and idempotency checks on the same element (root) and drop redundant child attribute

CSS now gates on the ancestor. Use the root attribute for both gating and idempotency; the child attribute is no longer needed.

   const canvasWrapperEl = document.createElement("div");
   if (
     childFromRoot &&
     childFromRoot.parentElement &&
-    !childFromRoot.hasAttribute(TLDRAW_DATA_ATTRIBUTE)
+    !rootElement.hasAttribute(TLDRAW_DATA_ATTRIBUTE)
   ) {
     rootElement.setAttribute(TLDRAW_DATA_ATTRIBUTE, "true");
-    childFromRoot.setAttribute(TLDRAW_DATA_ATTRIBUTE, "true");
     const parentEl = childFromRoot.parentElement;
     parentEl.appendChild(canvasWrapperEl);
     canvasWrapperEl.style.minHeight = minHeight;
     canvasWrapperEl.style.height = height;
   }

947-953: Avoid mounting into a detached node when already mounted

If the guard fails, canvasWrapperEl isn’t appended but renderWithUnmount still runs, creating an off-DOM tree. Bail out early.

-  const unmount = renderWithUnmount(
+  if (!canvasWrapperEl.isConnected) {
+    return () => {};
+  }
+  const unmount = renderWithUnmount(
     <ExtensionApiContextProvider {...onloadArgs}>
       <TldrawCanvas title={title} />
     </ExtensionApiContextProvider>,
     canvasWrapperEl,
   );
📜 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 62b1d34.

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

5-7: LGTM: selector shift to ancestor-based gating matches runtime attribute placement

Selectors now correctly check the root container attribute; this resolves timing issues with child attributes.

Also applies to: 10-12

@mdroidian mdroidian merged commit aaeb69a into main Aug 27, 2025
5 checks passed
@mdroidian mdroidian deleted the eng-796-canvas-hide-block-css-fix branch August 27, 2025 07:20
@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