Skip to content

Conversation

@trangdoan982
Copy link
Collaborator

@trangdoan982 trangdoan982 commented Jul 23, 2025

https://www.loom.com/share/70ce37001ff14852b52930db9f3d27be?sid=b7cf0506-9498-419a-b4cf-31ce95e93e37

Summary by CodeRabbit

  • New Features

    • Enhanced editor component with improved file synchronization, automatic saving, and state recovery.
    • Editor now responds to document visibility changes for better state management.
  • Bug Fixes

    • Improved error handling during save operations to prevent data loss and ensure file consistency.
  • Refactor

    • Updated editor component properties for better integration and maintainability.
  • Chores

    • Added new utility functions to support file content updates and data handling.

@linear
Copy link

linear bot commented Jul 23, 2025

@trangdoan982
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2025

📝 Walkthrough

Walkthrough

The changes introduce file persistence and editor state management to the Tldraw preview component. The component now receives plugin and file props, implements debounced saving of editor state to file, and manages UI/editor state synchronization. Utility functions for file content replacement and TLData updates are added, and the React root creation is guarded against missing file references.

Changes

File(s) Change Summary
apps/obsidian/src/components/TldrawView.tsx Modified createReactRoot to return early if this.file is undefined; passed plugin and file props to TldrawPreviewComponent.
apps/obsidian/src/components/TldrawViewComponent.tsx Enhanced TldrawPreviewComponent with file persistence, debounced save, editor state management, and updated props interface.
apps/obsidian/src/utils/tldraw.ts Added replaceBetweenKeywords and updateFileData utility functions; updated imports and closed createCanvas function properly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TldrawPreviewComponent
    participant FileSystem
    participant Plugin

    User->>TldrawPreviewComponent: Edit canvas
    TldrawPreviewComponent->>TldrawPreviewComponent: Debounced save triggered on change
    TldrawPreviewComponent->>FileSystem: Serialize and save editor state between delimiters
    FileSystem-->>TldrawPreviewComponent: Confirm write or return error
    alt Save error
        TldrawPreviewComponent->>FileSystem: Attempt recovery from file
    end
    User->>TldrawPreviewComponent: Visibility changes
    TldrawPreviewComponent->>TldrawPreviewComponent: Update editor focus and pen mode
Loading

Estimated code review effort

3 (~45 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
🪧 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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

Documentation and Community

  • 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: 4

🔭 Outside diff range comments (1)
apps/obsidian/src/components/TldrawView.tsx (1)

136-150: Avoid creating unused React roots to prevent memory leaks.

Creating a React root without rendering it can lead to memory leaks. Consider returning undefined instead of the unrendered root when this.file is not available.

Apply this diff to fix the issue:

 private createReactRoot(entryPoint: Element, store: TLStore) {
+  if (!this.file) return undefined;
   const root = createRoot(entryPoint);
-  if (!this.file) return root;

   root.render(
     <React.StrictMode>
       <TldrawPreviewComponent
         store={store}
         plugin={this.plugin}
         file={this.file}
       />
     </React.StrictMode>,
   );
   return root;
 }

Then update the caller at line 184 to handle the undefined case:

const root = this.createReactRoot(container, this.store);
if (root) {
  this.reactRoot = root;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b3c292 and 071f3a2.

📒 Files selected for processing (3)
  • apps/obsidian/src/components/TldrawView.tsx (1 hunks)
  • apps/obsidian/src/components/TldrawViewComponent.tsx (3 hunks)
  • apps/obsidian/src/utils/tldraw.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/obsidian/src/utils/tldraw.ts (3)

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/obsidian.mdc:0-0
Timestamp: 2025-07-19T22:34:16.794Z
Learning: Applies to apps/obsidian/package.json : Prefer existing dependencies from package.json when adding or using dependencies in the Obsidian plugin

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual process.env keys to avoid unnecessary coupling.

🧬 Code Graph Analysis (3)
apps/obsidian/src/components/TldrawView.tsx (1)
apps/obsidian/src/components/TldrawViewComponent.tsx (1)
  • TldrawPreviewComponent (19-181)
apps/obsidian/src/utils/tldraw.ts (1)
apps/obsidian/src/index.ts (1)
  • DiscourseGraphPlugin (25-287)
apps/obsidian/src/components/TldrawViewComponent.tsx (3)
apps/obsidian/src/index.ts (1)
  • DiscourseGraphPlugin (25-287)
apps/obsidian/src/utils/tldraw.ts (2)
  • updateFileData (136-146)
  • replaceBetweenKeywords (126-134)
apps/obsidian/src/constants.ts (3)
  • TLDATA_DELIMITER_START (63-64)
  • TLDATA_DELIMITER_END (65-66)
  • DEFAULT_SAVE_DELAY (72-72)

@trangdoan982 trangdoan982 requested a review from mdroidian July 23, 2025 18:42
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

Changes requested in our 1:1, noted by you inline.

@trangdoan982 trangdoan982 force-pushed the eng-598-data-persistence-tldraw branch from 059f473 to 41ca0d0 Compare July 28, 2025 15:39
@trangdoan982 trangdoan982 requested a review from mdroidian July 28, 2025 19:49
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

Good stuff.

RE: IDE linting, if you weren't seeing those lint errors we can postpone fixed them to before merge to main. But in the future let's try to fix new lint warnings that we create on the spot.

RE: package-lock.json
This is slightly concerning, as there were no package.json changes. I'm assuming this was missed from some previous PR? If not, I'd track down where these changes are coming from.

@trangdoan982 trangdoan982 force-pushed the eng-598-data-persistence-tldraw branch from 5a4c622 to a66d28b Compare August 4, 2025 15:25
@trangdoan982 trangdoan982 merged commit b348536 into tldraw-obsidian Aug 4, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Aug 4, 2025
@trangdoan982 trangdoan982 deleted the eng-598-data-persistence-tldraw branch August 4, 2025 15:25
const newData = getTLDataTemplate({
pluginVersion: plugin.manifest.version,
tldrawFile: createRawTldrawFile(currentStore),
uuid: window.crypto.randomUUID(),
Copy link
Contributor

Choose a reason for hiding this comment

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

@trangdoan982 Just noticed, since we are generating a new uuid on each saveChanges, stringifiedData === lastSavedDataRef.current will always be false.

maparent pushed a commit that referenced this pull request Aug 30, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
trangdoan982 added a commit that referenced this pull request Sep 1, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
trangdoan982 added a commit that referenced this pull request Sep 1, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
@coderabbitai coderabbitai bot mentioned this pull request Sep 25, 2025
trangdoan982 added a commit that referenced this pull request Oct 3, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
trangdoan982 added a commit that referenced this pull request Oct 9, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
trangdoan982 added a commit that referenced this pull request Oct 9, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
trangdoan982 added a commit that referenced this pull request Oct 14, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
trangdoan982 added a commit that referenced this pull request Oct 14, 2025
* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments
trangdoan982 added a commit that referenced this pull request Oct 16, 2025
* [ENG-495] Tldraw obsidian setup (#285)

* cleaned

* sm

* address PR comments

* [ENG-598] Data persistence for tldraw (#303)

* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments

* [ENG-624] TLDraw Obsidian asset store (#326)

* current state

* works now

* clean up

* address PR comments

* address PR reviews

* cleanup

* fix styling issues

* address PR comments

* correct styles

* [ENG-599] Discourse node shape (#341)

* current state

* works now

* clean up

* address PR comments

* address PR reviews

* fix styling issues

* latest progress

* update new shape

* shape defined

* address PR comments

* sm address PR review

* current progress

* reorg

* address other PR comments

* clean

* simplify flow

* address PR comments

* [ENG-604] Create node flow (#387)

* eng-604: create node flow

* pwd

* [ENG-658] Add existing node flow (#389)

* eng-658-add-existing-nodes-flow

* address PR comments

* small changes

* [ENG-601] Create settings for canvas and attachment default folder (#338)

* add new settings

* small add

* ENG-600: Discourse Relation shape definition (#408)

* ENG-605: Add new relation flow (#411)

* [ENG-603] Add existing relations (#412)

https://www.loom.com/share/3641f2a642714b0d849262344e8c6ee5?sid=0614c657-e541-4bfd-92df-9b1aa60945b6

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- New Features
  - Added a Relations overlay on the canvas that shows a “Relations” button when a discourse node is selected.
  - Introduced a Relations panel to view and manage relations for the selected node, including adding or removing links, with clear loading/error states.
  - Overlay appears above the canvas without disrupting existing tools.

- Chores
  - Consolidated relation-type lookup into shared utilities and updated imports. No user-facing changes.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

* [ENG-844] Add color setting for relation types (#429)

* add color setting

* address PR reviews

* address PR commens

* fix icons

* ENG-812 Update of database cli tools (#401)

* eng-812 : Update database cli tools: supabase, vercel, cucumber.

* newer cucumber constrains node

* [ENG-495] Tldraw obsidian setup (#285)

* cleaned

* sm

* address PR comments

* [ENG-598] Data persistence for tldraw (#303)

* data persistence to the file

* error handling

* address PR comments

* address some PR comments

* address other PR comments

* address PR comments

* switch to pnpm

* delete wrong rebase file

* fix pnpm lock

* fix type checks

* address all the PR comments

* delete redundant files

* fix types

* shift click to open file on the right split (#485)

* address PR comments

* final lint cleanup

---------

Co-authored-by: Marc-Antoine Parent <maparent@acm.org>
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.

3 participants