Skip to content

Conversation

@trangdoan982
Copy link
Collaborator

@trangdoan982 trangdoan982 commented Aug 8, 2025

https://www.loom.com/share/133f76d44b0b464192512721dd51f771?sid=bb166032-0937-4aa8-9c0c-d26f474bae5b

Summary by CodeRabbit

  • New Features

    • Introduced integrated asset management for drawings, allowing users to upload, cache, and resolve images and videos directly within the app.
    • Assets are now stored and tracked in a dedicated attachments folder, linked to your markdown files.
  • Bug Fixes

    • Improved reliability when switching or closing files by ensuring proper cleanup of asset resources.

@linear
Copy link

linear bot commented Aug 8, 2025

@supabase
Copy link

supabase bot commented Aug 8, 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 ↗︎.

@trangdoan982 trangdoan982 changed the base branch from main to tldraw-obsidian August 8, 2025 20:02
@trangdoan982
Copy link
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 8, 2025

📝 Walkthrough

Walkthrough

Asset store management was integrated into the TldrawView lifecycle, introducing creation, passing, and cleanup of an Obsidian-specific TLDraw asset store. The TldrawPreviewComponent now requires and utilizes this asset store. A new module implements the ObsidianTLAssetStore, handling asset upload, caching, and retrieval within the Obsidian vault and markdown files.

Changes

Cohort / File(s) Change Summary
TldrawView Asset Store Integration
apps/obsidian/src/components/TldrawView.tsx
Introduced private asset store field; asset store is created on file load, passed to preview component, and disposed on file unload/close. View refresh is now async to accommodate React rendering.
Preview Component Asset Store Prop
apps/obsidian/src/components/TldrawViewComponent.tsx
Updated component and props to require assetStore; assigns assetStore to TLDraw store assets on mount.
Obsidian Asset Store Implementation
apps/obsidian/src/utils/asset-store.ts
Added new module implementing ObsidianTLAssetStore and proxy for asset management: upload, resolve, cache, and dispose assets using Obsidian vault and markdown file block references.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TldrawView
    participant ObsidianTLAssetStore
    participant TldrawPreviewComponent

    User->>TldrawView: Open file
    TldrawView->>ObsidianTLAssetStore: Instantiate asset store with file context
    TldrawView->>TldrawPreviewComponent: Create React root, pass assetStore
    TldrawPreviewComponent->>ObsidianTLAssetStore: Use assetStore for assets

    User->>TldrawView: Close or unload file
    TldrawView->>ObsidianTLAssetStore: Dispose and clear asset store
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


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.
  • 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.

Support

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

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

🧹 Nitpick comments (5)
apps/obsidian/src/utils/asset-store.ts (2)

34-38: Avoid hard-coding the “attachments” folder

The path is baked in; users who changed their attachment location (or prefer per-vault settings) will get orphan files.
Pass the folder via plugin / workspace settings or fall back to app.vault.getConfig("attachmentFolderPath") before creating one.


87-99: #addToTopOfFile risks corrupting front-matter offsets

Using metadataCache.getFileCache inside the same process call re-reads stale cache; front-matter positions may be wrong after the edit, producing duplicated front-matter or misplaced block ref lines.
Safer: parse the raw text once without relying on cache, or call metadataCache.triggerCacheUpdate(file) after writing.

apps/obsidian/src/components/TldrawView.tsx (3)

78-82: persistenceKey should be filesystem-safe

file.path contains slashes; some back-end stores treat / as a hierarchy delimiter.
Encode (e.g. encodeURIComponent(file.path)) or hash the path to avoid unexpected collisions.


121-122: Remove leftover console.log

Debug statement will spam the console for every canvas open.


168-170: Zero-delay setTimeout awaits is unnecessary

await new Promise(r => setTimeout(r, 0)) adds one tick with no observable benefit here; React render is already synchronous for root.render.
Drop the await unless you’re waiting for a subsequent measurement/layout step.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b348536 and 9fb95e7.

📒 Files selected for processing (3)
  • apps/obsidian/src/components/TldrawView.tsx (7 hunks)
  • apps/obsidian/src/components/TldrawViewComponent.tsx (3 hunks)
  • apps/obsidian/src/utils/asset-store.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
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/Attachments/icons/*.svg : Store all icon files in the Attachments/icons folder
📚 Learning: 2025-07-19T22:34:08.725Z
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to {apps/website,packages/ui}/**/*.{tsx,jsx} : When refactoring inline styles, use tailwind classes

Applied to files:

  • apps/obsidian/src/components/TldrawViewComponent.tsx
📚 Learning: 2025-07-19T22:34:08.725Z
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to {apps/website,packages/ui}/**/*.{tsx,jsx} : Use platform-native UI components first with shadcn/ui as a fallback

Applied to files:

  • apps/obsidian/src/components/TldrawViewComponent.tsx
📚 Learning: 2025-07-19T22:34:08.725Z
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to apps/website/**/*.{tsx,jsx,ts,js} : Use Tailwind CSS for styling where possible

Applied to files:

  • apps/obsidian/src/components/TldrawViewComponent.tsx
📚 Learning: 2025-07-19T22:34:23.619Z
Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/**/*.{js,jsx,ts,tsx} : Use BlueprintJS 3 components and Tailwind CSS for platform-native UI in the Roam Research extension

Applied to files:

  • apps/obsidian/src/components/TldrawViewComponent.tsx
📚 Learning: 2025-07-19T22:34:16.794Z
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/Attachments/icons/*.svg : Store all icon files in the Attachments/icons folder

Applied to files:

  • apps/obsidian/src/utils/asset-store.ts
  • apps/obsidian/src/components/TldrawView.tsx
🔇 Additional comments (1)
apps/obsidian/src/components/TldrawView.tsx (1)

182-186: Double disposal is safe but redundant

assetStore.dispose() is invoked in both onUnloadFile and onClose.
If onClose always follows onUnloadFile, one call suffices; otherwise leave as-is.
Consider guarding with a flag to avoid confusion.

Also applies to: 214-218

@trangdoan982 trangdoan982 requested a review from mdroidian August 8, 2025 20:33
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, a few changes requested.

Couple additional things to list here

  • I noticed the image gets added to the markdown with ! which "embeds" it. After a few images, this will get quite noisy. Let's remove the !. A user can preview with a modifier+hover if they want.

  • I'd love to test this myself, but unfortunately I can't load it. I think this is related to the css issue we discussed.

image

@trangdoan982 trangdoan982 requested a review from mdroidian August 11, 2025 15:07
@trangdoan982
Copy link
Collaborator Author

@mdroidian i just pushed a fix for the styling issue, can you check if it works on your local now?

@mdroidian
Copy link
Contributor

mdroidian commented Aug 13, 2025

@mdroidian i just pushed a fix for the styling issue, can you check if it works on your local now?

No change for me. I even tried deleting node_modules / package-lock.json just to see if there was something funky there.

We can debug it together tomorrow.

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.

🚀

@trangdoan982 trangdoan982 merged commit e32ea83 into tldraw-obsidian Aug 15, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Aug 15, 2025
@trangdoan982 trangdoan982 deleted the eng-624-asset-store branch August 15, 2025 18:13
maparent pushed a commit that referenced this pull request Aug 30, 2025
* current state

* works now

* clean up

* address PR comments

* address PR reviews

* cleanup

* fix styling issues

* address PR comments
trangdoan982 added a commit that referenced this pull request Sep 1, 2025
* current state

* works now

* clean up

* address PR comments

* address PR reviews

* cleanup

* fix styling issues

* address PR comments
trangdoan982 added a commit that referenced this pull request Sep 1, 2025
* current state

* works now

* clean up

* address PR comments

* address PR reviews

* cleanup

* fix styling issues

* address PR comments
@coderabbitai coderabbitai bot mentioned this pull request Sep 25, 2025
trangdoan982 added a commit that referenced this pull request Oct 9, 2025
* current state

* works now

* clean up

* address PR comments

* address PR reviews

* cleanup

* fix styling issues

* address PR comments
trangdoan982 added a commit that referenced this pull request Oct 14, 2025
* current state

* works now

* clean up

* address PR comments

* address PR reviews

* cleanup

* fix styling issues

* 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