Skip to content

ENG-797: Handle multiple canvases loaded at the same time#928

Open
sid597 wants to merge 3 commits intomainfrom
eng-797-handle-multiple-canvas-loaded-at-the-same-time
Open

ENG-797: Handle multiple canvases loaded at the same time#928
sid597 wants to merge 3 commits intomainfrom
eng-797-handle-multiple-canvas-loaded-at-the-same-time

Conversation

@sid597
Copy link
Copy Markdown
Collaborator

@sid597 sid597 commented Mar 30, 2026

Scope active canvas focus so clipboard, query builder actions, and shared context don't leak across simultaneously open canvases.


Open with Devin

Summary by CodeRabbit

  • Refactor
    • Improved canvas focus and blur handling when working with multiple canvases
    • Enhanced action routing to support targeted canvas page selection
    • Disabled auto-focus behavior on Tldraw editor initialization

Scope active canvas focus so clipboard, query builder actions, and
shared context don't leak across simultaneously open canvases.
@linear
Copy link
Copy Markdown

linear bot commented Mar 30, 2026

@supabase
Copy link
Copy Markdown

supabase bot commented Mar 30, 2026

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 ↗︎.

@sid597
Copy link
Copy Markdown
Collaborator Author

sid597 commented Mar 30, 2026

@coderabbitai full review

export const discourseContext: DiscourseContextType = {
nodes: {},
relations: {},
lastAppEvent: "",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Surface 1 handled

let activeCanvasPageUid: string | null = null;
let activeCanvasEditor: Editor | null = null;

const setActiveCanvas = ({
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Surface 3 handled, we track the active canvas and ensure only that canvas is focused, so only this canvas responds to the clipboard events

devin-ai-integration[bot]

This comment was marked as resolved.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

This PR refactors discourse context state management by removing lastAppEvent and lastActions from shared context and replacing them with module-level and component-local state. It introduces active-canvas tracking and event routing based on target canvas page UID, with automatic focus/blur management when switching between Tldraw editors.

Changes

Cohort / File(s) Summary
Discourse Context Cleanup
apps/roam/src/components/Export.tsx, apps/roam/src/components/canvas/Tldraw.tsx
Removed lastAppEvent and lastActions properties from DiscourseContextType. Eliminated discourse relation assignment to shared context during canvas initialization and removed corresponding import of discourseContext in Export module.
Active Canvas Tracking & Event Routing
apps/roam/src/components/canvas/Tldraw.tsx
Added module-level activeCanvasPageUid and activeCanvasEditor with setActiveCanvas helper for managing editor focus/blur. Updated roamjs:query-builder:action listener to route events by optional targetCanvasPageUid. Added onPointerDownCapture handler and onMount logic to activate canvas on interaction. Disabled Tldraw auto-focus and added cleanup on canvas unmount.
Event Payload Enhancement
apps/roam/src/components/results-view/ResultsTable.tsx
Updated Button click handler to extract targetCanvasPageUid from closest [data-page-uid] ancestor and include it in the dispatched CustomEvent detail payload for targeted canvas event routing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main objective of the changeset: implementing handling for multiple simultaneously-open canvases with proper focus scoping.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

✅ Actions performed

Full review triggered.

if (!isTLStore) {
const relations = getDiscourseRelations();
discourseContext.relations = relations.reduce(
(acc, r) => {
Copy link
Copy Markdown
Collaborator Author

@sid597 sid597 Mar 30, 2026

Choose a reason for hiding this comment

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

Mutating this could effect the state for other open canvases??? we do set this up in tldraw.tsx line 455

This is for you Michael it seems correct to me but can give an authortative answer here

<Button
{...buttonProps}
onClick={() => {
onClick={(event) => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Pass this to the correct canvas

coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

- Check activeCanvasEditor identity in cleanup to avoid clearing
  a canvas that was already replaced by another instance
- Guard onPointerDownCapture against null editor ref
- Narrow closest() selector to .roamjs-tldraw-canvas-container
  so nested data-page-uid attributes don't match incorrectly
mdroidian added a commit that referenced this pull request Mar 30, 2026
- Introduced a new `docsRouteMap.ts` file to manage documentation sections and redirects for Roam and Obsidian platforms.
- Updated `next.config.ts` to include dynamic redirects based on the new route map.
- Refactored the layout components for documentation pages to utilize a consistent theme layout.
- Removed outdated `page.tsx` files for Roam and Obsidian, replacing them with new landing pages that leverage Nextra for content rendering.
- Added new metadata and content files for various documentation sections, enhancing the overall documentation structure and accessibility.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant