Skip to content

Conversation

@sid597
Copy link
Collaborator

@sid597 sid597 commented Sep 1, 2025

https://www.loom.com/share/0310aa0d89b843cc8eb66f42ff9a2f39?sid=bc015e12-05d3-44e7-b84a-a983524d95b5

Summary by CodeRabbit

  • Bug Fixes

    • Node tag popup now appears only for valid tags.
    • UI stays in sync after navigation and configuration updates, reducing stale or missing tag info.
  • Refactor

    • Centralized caching of discourse nodes to improve responsiveness and consistency across the app.

@linear
Copy link

linear bot commented Sep 1, 2025

@supabase
Copy link

supabase bot commented Sep 1, 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 ↗︎.

@sid597
Copy link
Collaborator Author

sid597 commented Sep 1, 2025

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

📝 Walkthrough

Walkthrough

Adds a local cache of discourse nodes and their tags, initializes and refreshes it during observer setup and navigation events, and updates node tag popup rendering to use the cached nodes. Adjusts imports to use a named DiscourseNode type and changes the popup function signature to accept pre-fetched nodes.

Changes

Cohort / File(s) Summary
Discourse node caching and observer wiring
apps/roam/src/utils/initializeObserversAndListeners.ts
Introduces in-memory caches for discourse nodes and tag set; adds refreshDiscourseNodeCache(); triggers cache refresh at init, after config page creation, and on relevant URL/hash changes; updates imports to include named DiscourseNode from ~/utils/getDiscourseNodes.
Popup rendering signature change
apps/roam/src/utils/renderNodeTagPopup.tsx
Changes renderNodeTagPopupButton signature to accept discourseNodes: DiscourseNode[]; removes internal fetching and tag-set gate; finds matched node from provided list; updates import of DiscourseNode as a named export.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Roam as Roam App
  participant Init as initObservers
  participant Cache as DiscourseNode Cache
  participant Renderer as renderNodeTagPopupButton

  User->>Roam: Open/Navigate
  Roam->>Init: Initialize observers/listeners
  Init->>Cache: refreshDiscourseNodeCache()
  Cache-->>Init: discourseNodes + lowercase tag set ready

  Note over Roam,Cache: On config page creation or relevant hash/URL changes
  Roam->>Cache: refreshDiscourseNodeCache()

  User->>Roam: Hover/interaction on SPAN[data-tag]
  Roam->>Renderer: renderNodeTagPopupButton(SPAN, discourseNodes, extensionAPI)
  Renderer->>Renderer: Find matched node by tag
  alt match found
    Renderer-->>User: Render node tag popup
  else no match
    Renderer-->>User: Do nothing
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs


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.
    • 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.
  • 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 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/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 0

🧹 Nitpick comments (7)
apps/roam/src/utils/renderNodeTagPopup.tsx (3)

8-8: Use a type-only import to avoid emitting runtime code.

-import { DiscourseNode } from "./getDiscourseNodes";
+import type { DiscourseNode } from "./getDiscourseNodes";

35-41: Edge case: tags with multiple leading # when data-tag is absent.

When falling back to textContent (rare), "##foo" becomes "#foo" and won’t match node.tag "foo". Strip all leading # only in the fallback path.

-  const tagAttr = parent.getAttribute("data-tag") || textContent;
-  const tag = tagAttr.replace(/^#/, "").toLowerCase();
+  const attrTag = parent.getAttribute("data-tag");
+  const tagSource = attrTag ?? textContent;
+  const tag = (attrTag ? tagSource.replace(/^#/, "") : tagSource.replace(/^#+/, "")).toLowerCase();

Note: This keeps the prior behavior for data-tag while making the fallback robust, consistent with our prior guidance to preserve user-intended extra hashes in authoring flows.


47-49: Initial title derivation may remove the wrong occurrence if the tag text repeats.

Optional: remove only the occurrence corresponding to this span by matching the leading “#” variant first, or by slicing based on the tag’s index in the raw string.

apps/roam/src/utils/initializeObserversAndListeners.ts (4)

28-28: Use a type-only import for DiscourseNode.

-import getDiscourseNodes, { DiscourseNode } from "~/utils/getDiscourseNodes";
+import getDiscourseNodes, { type DiscourseNode } from "~/utils/getDiscourseNodes";

116-121: Gated rendering is correct; pass cached nodes.

Minor: consider early-return style to reduce nesting, but current form is fine.


171-172: Avoid redundant getDiscourseNodes call on hashchange.

You call getDiscourseNodes() in the condition and then refresh the cache again. Use the cached discourseNodes for the check.

-    if (
-      evt.oldURL.endsWith(configPageUid) ||
-      getDiscourseNodes().some(({ type }) => evt.oldURL.endsWith(type))
-    ) {
+    if (
+      evt.oldURL.endsWith(configPageUid) ||
+      discourseNodes.some(({ type }) => evt.oldURL.endsWith(type))
+    ) {
       refreshConfigTree();
       refreshDiscourseNodeCache();
     }

Also applies to: 182-183


48-56: Consider scoping caches inside initObservers to avoid cross-init state.

If initObservers can run multiple times in a session, module-level caches may leak state across runs. Keeping them inside initObservers and exposing a lightweight accessor would isolate lifecycles. Low priority.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 82f0e22 and 26226bf.

📒 Files selected for processing (2)
  • apps/roam/src/utils/initializeObserversAndListeners.ts (6 hunks)
  • apps/roam/src/utils/renderNodeTagPopup.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-25T15:53:21.799Z
Learnt from: sid597
PR: DiscourseGraphs/discourse-graph#372
File: apps/roam/src/components/DiscourseNodeMenu.tsx:116-116
Timestamp: 2025-08-25T15:53:21.799Z
Learning: In apps/roam/src/components/DiscourseNodeMenu.tsx, when handling tag insertion, multiple leading hashtags (like ##foo) should be preserved as they represent user intent, not normalized to a single hashtag. The current regex /^#/ is correct as it only removes one leading # before adding one back, maintaining any additional hashtags the user intended.

Applied to files:

  • apps/roam/src/utils/initializeObserversAndListeners.ts
  • apps/roam/src/utils/renderNodeTagPopup.tsx
🔇 Additional comments (2)
apps/roam/src/utils/renderNodeTagPopup.tsx (1)

12-14: Signature change verified: all call sites updated
Only one usage found (in initializeObserversAndListeners.ts) and it matches the new three-argument signature.

apps/roam/src/utils/initializeObserversAndListeners.ts (1)

48-56: Local cache + initial refresh look good.

Caching nodes and a lowercase tag set, plus refreshing at init, should eliminate redundant queries in hot paths.

Also applies to: 80-80

@sid597 sid597 force-pushed the eng-798-node-tags-breaks-color-highlighter branch from 26226bf to c797cb9 Compare September 4, 2025 08:25
Copy link
Collaborator Author

sid597 commented Sep 4, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sid597 sid597 force-pushed the eng-798-node-tags-breaks-color-highlighter branch 2 times, most recently from 99be069 to 41e70bf Compare September 7, 2025 10:23
@sid597 sid597 requested a review from mdroidian September 7, 2025 10:24
@sid597 sid597 force-pushed the eng-798-node-tags-breaks-color-highlighter branch from 41e70bf to 8592c3d Compare September 8, 2025 12:01
@sid597 sid597 force-pushed the eng-798-node-tags-breaks-color-highlighter branch from 8592c3d to 2f88247 Compare September 8, 2025 12:02
@sid597 sid597 requested a review from mdroidian September 8, 2025 12:03
* modify dom only for node tags

* add background color to a nodetag

* use it as color not background color

* remove unused refresh

* Roam: ENG-693 handle node tags with # in front and update placeholder to use # (#420)

* use text not tag

* Move the new block as first child of the current block (#422)
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.

👍

@sid597 sid597 merged commit 0e381c6 into main Sep 8, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Sep 8, 2025
trangdoan982 pushed a commit that referenced this pull request Oct 3, 2025
* use getDiscourseNodes

* Eng-737 use node color to style node tags (#424)

* modify dom only for node tags

* add background color to a nodetag

* use it as color not background color

* remove unused refresh

* Roam: ENG-693 handle node tags with # in front and update placeholder to use # (#420)

* use text not tag

* Move the new block as first child of the current block (#422)
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