ENG-797: Handle multiple canvases loaded at the same time#928
ENG-797: Handle multiple canvases loaded at the same time#928
Conversation
Scope active canvas focus so clipboard, query builder actions, and shared context don't leak across simultaneously open canvases.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@coderabbitai full review |
| export const discourseContext: DiscourseContextType = { | ||
| nodes: {}, | ||
| relations: {}, | ||
| lastAppEvent: "", |
| let activeCanvasPageUid: string | null = null; | ||
| let activeCanvasEditor: Editor | null = null; | ||
|
|
||
| const setActiveCanvas = ({ |
There was a problem hiding this comment.
Surface 3 handled, we track the active canvas and ensure only that canvas is focused, so only this canvas responds to the clipboard events
📝 WalkthroughWalkthroughThis PR refactors discourse context state management by removing Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ 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. Comment |
✅ Actions performedFull review triggered. |
| if (!isTLStore) { | ||
| const relations = getDiscourseRelations(); | ||
| discourseContext.relations = relations.reduce( | ||
| (acc, r) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Needs to stay because this is a way to update the relations when we export to the canvas
| <Button | ||
| {...buttonProps} | ||
| onClick={() => { | ||
| onClick={(event) => { |
There was a problem hiding this comment.
Pass this to the correct canvas
- 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
- 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.
| nodes: {}, | ||
| relations: {}, | ||
| lastAppEvent: "", | ||
| lastActions: [], |
There was a problem hiding this comment.
needs to stay, because we use this to log on error
| nodes: {}, | ||
| relations: {}, | ||
| lastAppEvent: "", | ||
| lastActions: [], |
There was a problem hiding this comment.
We use this to send log of last actions taken by user in case of error. Should not remove this.
mdroidian
left a comment
There was a problem hiding this comment.
As discussed in our meeting
Let's
- remove the
useEffectand do a closer solution to: https://tldraw.dev/examples/multiple - re-add
lastActionsand make sure we test multiple canvas' against it - re-add the export.tsx discourseContext.relations
- test
sending from Share Via in query builder only sends to the target canvas- we tested live, seems fine
- we also noticed that
copy all/deletewas shared across canvas'- this is likely the same "focus" problem, but worth checking
https://www.loom.com/share/8af7d98fbab74f429a8c7a4e4982c260
Scope active canvas focus so clipboard, query builder actions, and shared context don't leak across simultaneously open canvases.
Summary by CodeRabbit