-
Notifications
You must be signed in to change notification settings - Fork 4
ENG-790 - Referencing an EVD or RES node on canvas is creating a duplicate node with additional tag #390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENG-790 - Referencing an EVD or RES node on canvas is creating a duplicate node with additional tag #390
Conversation
- Replaced promise chaining with async/await and try/catch for improved error handling. - Simplified the fetching logic for main and referenced node options. - Updated useEffect dependencies for better clarity and performance. - Changed referencedNode retrieval to use useMemo for optimization.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@CodeRabbit full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughRefactors LabelDialogAutocomplete to use an async fetchOptions with async/await and proper loading/error handling, replacing timer- and promise-chained logic. Adds memoized referencedNode computation in LabelDialog. Updates effects and props wiring. Introduces separate queries for main nodeType and optional referenced node type. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User
participant LD as LabelDialog
participant LDA as LabelDialogAutocomplete
participant Q as fireQuery
U->>LD: Open Label Dialog
LD->>LD: useMemo compute referencedNode
LD->>LDA: Render with nodeType, isAddReferencedNode, referencedNode
rect rgba(200,230,255,0.3)
note right of LDA: Fetch main options
LDA->>LDA: setLoading(true)
LDA->>Q: fireQuery(nodeType, uid₁)
Q-->>LDA: options
LDA->>LDA: setOptions(...)
LDA->>LDA: setLoading(false)
end
alt isAddReferencedNode && referencedNode
rect rgba(220,255,220,0.3)
note right of LDA: Fetch referenced node options
LDA->>LDA: setLoading(true)
LDA->>Q: fireQuery(referencedNode.nodeType, uid₂)
Q-->>LDA: referenced options
LDA->>LDA: setReferencedNodeOptions(...)
LDA->>LDA: setLoading(false)
end
else No referenced fetch
note right of LDA: Skip referenced fetch
end
opt Error case
LDA->>LDA: catch -> console.error(...)
LDA->>LDA: setLoading(false)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/roam/src/components/canvas/LabelDialog.tsx (1)
328-347: Avoid dynamic RegExp usage and variable shadowing in LabelDialog.tsx
- In the
useMemoblock (around lines 335–343), rename the innerreferencedNodetorefNodeand replace the unsafe regex test with a case-insensitive string comparison:- const referencedNode = Object.values(discourseContext.nodes).find( - ({ text }) => new RegExp(text, "i").test(val), - ); - if (referencedNode) { - return { name: referencedNode.text, nodeType: referencedNode.type }; + const refNode = Object.values(discourseContext.nodes).find( + ({ text }) => text.toLowerCase() === val.toLowerCase(), + ); + if (refNode) { + return { name: refNode.text, nodeType: refNode.type };
- In the
setValuecallback (around line 133), replace the dynamic regex with a direct comparison:- if ( - referencedNode && - new RegExp(referencedNode.name, "i").test(val) && - isAddReferencedNode - ) + if ( + referencedNode && + referencedNode.name.toLowerCase() === val.toLowerCase() && + isAddReferencedNode + )
🧹 Nitpick comments (1)
apps/roam/src/components/canvas/LabelDialog.tsx (1)
221-224: Prefer e.currentTarget over e.target in Checkbox onChangeUsing
e.targetcan be wrong when events bubble from nested elements.currentTargetis the checkbox.- onChange={(e) => { - const checked = e.target as HTMLInputElement; - setIsEditExistingLabel(checked.checked); - }} + onChange={(e) => setIsEditExistingLabel(e.currentTarget.checked)}- onChange={(e) => { - const checked = e.target as HTMLInputElement; - setAddReferencedNode(checked.checked); - }} + onChange={(e) => setAddReferencedNode(e.currentTarget.checked)}Also applies to: 238-241
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/roam/src/components/canvas/LabelDialog.tsx(3 hunks)
- Introduced request ID tracking to prevent stale state updates during asynchronous fetching. - Added cleanup logic in useEffect to manage component lifecycle and avoid memory leaks. - Improved error handling to ensure console errors are logged only for the latest request. - Maintained existing async/await structure for fetching options, enhancing clarity and performance.
Summary by CodeRabbit
Bug Fixes
Performance & UX
Refactor