Skip to content

Conversation

@mdroidian
Copy link
Contributor

@mdroidian mdroidian commented Sep 7, 2025

Before:
We were updating state which would re-render tldraw. We also are currently not handling/saving the camera (at the moment).
So this would jump the camera to the original/last save state on minimize or maximize. Very jarring and poor UX.

After:
Instead of state we manipulate the DOM directly. Additionally, we use some of tldraw's built in utilities to to move the camera based on the new viewport. It's not 100% but it is much less jarring. We could spend a bit more time finessing it, but it is now diminishing returns. Sidebar was not fully handled, also diminishing returns.

https://www.loom.com/share/9ff85d293fb14f11af0d7d321b9e6a6e

If we want to do sidebar:

  • rm-sidebar-outline-wrapper = position:static
  • .rm-sidebar-window = position:static;
  • .rm-sidebar-window = rm margin left/right

and hope they don't have 2 canvas' open in sidebar.

Summary by CodeRabbit

  • New Features

    • Added a maximize/fullscreen toggle for the canvas with smoother transitions and automatic viewport adjustment.
  • Bug Fixes

    • Canvas now reliably fills the screen when maximized and restores the previous layout on exit.
    • Prevents layout shifting or overlap in the main content and sidebar during maximize/unmaximize.

…pdates

- Introduced `handleMaximizedChange` to manage fullscreen toggling and DOM manipulation.
- Added `updateViewportScreenBounds` for viewport updates using Tldraw's built-in methods.
- Updated styles to support maximized state in Tldraw canvas.
- Removed unnecessary `maximized` state from props in `createUiOverrides`.
@linear
Copy link

linear bot commented Sep 7, 2025

@supabase
Copy link

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

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 7, 2025

📝 Walkthrough

Walkthrough

Refactors Tldraw canvas maximize behavior: replaces React state with a DOM-driven toggle, adds viewport bounds synchronization via tldraw Box, updates UI overrides API to a single toggle function, and adds CSS rules to adjust layout when maximized. Container classes/styles are simplified accordingly.

Changes

Cohort / File(s) Summary of Changes
Canvas maximize refactor
apps/roam/src/components/canvas/Tldraw.tsx
Replaced local maximized state with DOM-based toggle; added updateViewportScreenBounds using tldraw Box; implemented handleMaximizedChange to switch classes and update viewport; updated createUiOverrides call to pass toggleMaximized; simplified container classes; removed maximized-dependent inline styles.
UI overrides API
apps/roam/src/components/canvas/uiOverrides.tsx
Changed createUiOverrides signature: removed maximized and setMaximized, added toggleMaximized callback; updated toggle-full-screen action to call toggleMaximized().
Styles for maximized mode
apps/roam/src/components/canvas/tldrawStyles.ts
Switched export to include /* css */ annotation; appended CSS rules setting position: static for .dg-tldraw-maximized on article and sidebar containers to support maximize layout.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as UI Menu/Command
  participant Canvas as TldrawCanvas
  participant DOM as DOM Container
  participant Viewport as tldraw Viewport

  User->>UI: Select "Toggle Full Screen"
  UI->>Canvas: toggleMaximized()
  rect rgba(200,235,255,0.3)
    note right of Canvas: Maximize/unmaximize
    Canvas->>DOM: Toggle classes (relative/absolute/inset-0,<br/>.dg-tldraw-maximized)
    Canvas->>Viewport: updateViewportScreenBounds(Box.from DOM bounds)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 486be1b and 262fca8.

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

424-425: Centralizing fullscreen toggle in a single callback is cleaner.

Directly calling toggleMaximized() from the action keeps UI overrides thin and avoids stale state.


320-328: No lingering old maximize API references
Verified via rg -nP '\b(maximized|setMaximized)\b' that only CSS class names include “dg-tldraw-maximized” and no maximized or setMaximized calls remain.

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

3-3: Non-functional CSS annotation LGTM.

The /* css */ marker improves editor tooling without changing behavior.


80-85: Scope and lifecycle check for dg-tldraw-maximized.

Setting position: static on the article/sidebar wrappers is fine, but if the component unmounts while maximized the class may persist and affect layout. Ensure the class is always removed on unmount, and verify no regressions for sticky elements in those wrappers.

Suggested safety net in the React component cleanup (see Tldraw.tsx comment) and optionally here in the unmount path.

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

45-46: Importing Box from tldraw is appropriate.

This aligns with updateViewportScreenBounds expecting a Box.


422-424: Wiring toggleMaximized through UI overrides is correct.

Keeps maximize logic local to the canvas component and avoids accidental editor re-creation.


559-561: Container baseline classes LGTM.

Always starting from relative simplifies the toggle logic and reduces diff churn in className.

…ments in requestAnimationFrame for smoother performance.
@mdroidian mdroidian merged commit 27d9beb into main Sep 7, 2025
4 checks passed
@mdroidian mdroidian deleted the eng-831-focus-point-of-canvas-is-jumping-around branch September 7, 2025 07:53
@github-project-automation github-project-automation bot moved this to Done in General Sep 7, 2025
trangdoan982 pushed a commit that referenced this pull request Oct 3, 2025
* Refactor Tldraw component to handle maximization state and viewport updates

- Introduced `handleMaximizedChange` to manage fullscreen toggling and DOM manipulation.
- Added `updateViewportScreenBounds` for viewport updates using Tldraw's built-in methods.
- Updated styles to support maximized state in Tldraw canvas.
- Removed unnecessary `maximized` state from props in `createUiOverrides`.

* - Renamed `setMaximized` to `toggleMaximized` for clarity in both Tldraw and uiOverrides components.

* Optimize viewport updates in Tldraw component by wrapping DOM measurements in requestAnimationFrame for smoother performance.
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