Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/roam/src/utils/pullWatchBlockPropsBasedSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TOP_LEVEL_BLOCK_PROP_KEYS } from "~/data/blockPropsSettingsConfig";

export const setupPullWatchBlockPropsBasedSettings = (
blockUids: Record<string, string>,
) => {
Comment on lines +3 to +5
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add explicit return type per coding guidelines.

The function is missing an explicit return type. Per the coding guidelines, all functions should have explicit return types.

🔎 Proposed fix
-export const setupPullWatchBlockPropsBasedSettings = (
-  blockUids: Record<string, string>,
-) => {
+export const setupPullWatchBlockPropsBasedSettings = (
+  blockUids: Record<string, string>,
+): void => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const setupPullWatchBlockPropsBasedSettings = (
blockUids: Record<string, string>,
) => {
export const setupPullWatchBlockPropsBasedSettings = (
blockUids: Record<string, string>,
): void => {
🤖 Prompt for AI Agents
In apps/roam/src/utils/pullWatchBlockPropsBasedSettings.ts around lines 3 to 5,
the exported function lacks an explicit return type; add a return type
annotation after the parameter list (e.g. export const
setupPullWatchBlockPropsBasedSettings = (blockUids: Record<string, string>):
void => { ... }) — if the function actually returns a value or an unsubscribe
function, replace void with the correct type (e.g. Promise<void> or () => void)
to satisfy the coding guidelines.

const featureFlagsBlockUid =
blockUids[TOP_LEVEL_BLOCK_PROP_KEYS.featureFlags];

if (featureFlagsBlockUid) {
window.roamAlphaAPI.data.addPullWatch(
"[:block/props]",
`[:block/uid "${featureFlagsBlockUid}"]`,
(before, after) => {
console.log("feature flags changed", before, after);
},
);
}
Comment on lines +9 to +17
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find and read the pullWatchBlockPropsBasedSettings file
find . -name "*pullWatchBlockPropsBasedSettings*" -type f

Repository: DiscourseGraphs/discourse-graph

Length of output: 132


🏁 Script executed:

#!/bin/bash
# Read the file in question and context
fd "pullWatchBlockPropsBasedSettings" --exec cat -n {} \;

Repository: DiscourseGraphs/discourse-graph

Length of output: 720


🏁 Script executed:

#!/bin/bash
# Search for setupPullWatchBlockPropsBasedSettings usage in the codebase
rg -n "setupPullWatchBlockPropsBasedSettings" -A 3 -B 3 --type ts --type tsx

Repository: DiscourseGraphs/discourse-graph

Length of output: 102


🏁 Script executed:

#!/bin/bash
# Search for how setupPullWatchBlockPropsBasedSettings is called
rg -n "setupPullWatchBlockPropsBasedSettings" -A 5 -B 2

Repository: DiscourseGraphs/discourse-graph

Length of output: 802


🏁 Script executed:

#!/bin/bash
# Search for other addPullWatch usage in codebase to see cleanup patterns
rg -n "addPullWatch" -A 5 -B 2

Repository: DiscourseGraphs/discourse-graph

Length of output: 1402


🏁 Script executed:

#!/bin/bash
# Search for callers of setupPullWatchBlockPropsBasedSettings - where is it invoked?
rg -n "setupPullWatchBlockPropsBasedSettings\(" -B 5 -A 5

Repository: DiscourseGraphs/discourse-graph

Length of output: 57


🏁 Script executed:

#!/bin/bash
# Get more context around the useRoamStore usage to understand the cleanup pattern
cat -n apps/roam/src/components/canvas/useRoamStore.ts | sed -n '410,430p'

Repository: DiscourseGraphs/discourse-graph

Length of output: 880


🏁 Script executed:

#!/bin/bash
# Search for imports and actual usage of setupPullWatchBlockPropsBasedSettings
rg -n "setupPullWatchBlockPropsBasedSettings" --type ts

Repository: DiscourseGraphs/discourse-graph

Length of output: 187


🏁 Script executed:

#!/bin/bash
# Look for where this function might be called - check if it's exported and used
git grep -n "setupPullWatchBlockPropsBasedSettings"

Repository: DiscourseGraphs/discourse-graph

Length of output: 187


🏁 Script executed:

#!/bin/bash
# Check the full context of useRoamStore to see the pullWatchProps definition
cat -n apps/roam/src/components/canvas/useRoamStore.ts | sed -n '400,430p'

Repository: DiscourseGraphs/discourse-graph

Length of output: 1479


🏁 Script executed:

#!/bin/bash
# Search more broadly - check all files including .tsx for any reference
rg "setupPullWatchBlockPropsBasedSettings" --type-list
rg "setupPullWatchBlockPropsBasedSettings" .

Repository: DiscourseGraphs/discourse-graph

Length of output: 594


🏁 Script executed:

#!/bin/bash
# Check the context around line 400-430 to understand the full picture
cat -n apps/roam/src/components/canvas/useRoamStore.ts | sed -n '395,435p'

Repository: DiscourseGraphs/discourse-graph

Length of output: 1615


🏁 Script executed:

#!/bin/bash
# Check if setupPullWatchBlockPropsBasedSettings is actually called anywhere
rg "setupPullWatchBlockPropsBasedSettings\(" --type ts -B 3 -A 3

Repository: DiscourseGraphs/discourse-graph

Length of output: 57


🏁 Script executed:

#!/bin/bash
# Look for imports of setupPullWatchBlockPropsBasedSettings
rg "import.*setupPullWatchBlockPropsBasedSettings"

Repository: DiscourseGraphs/discourse-graph

Length of output: 57


🏁 Script executed:

#!/bin/bash
# Check the type definition for AddPullWatch to understand return value
rg -n "type AddPullWatch|interface AddPullWatch" -A 5

Repository: DiscourseGraphs/discourse-graph

Length of output: 57


🏁 Script executed:

#!/bin/bash
# Check if setupPullWatchBlockPropsBasedSettings might be called dynamically or exported in a barrel export
cat apps/roam/src/utils/pullWatchBlockPropsBasedSettings.ts

Repository: DiscourseGraphs/discourse-graph

Length of output: 594


🏁 Script executed:

#!/bin/bash
# Check index files that might re-export this
find apps/roam/src -name "index.ts" -o -name "index.tsx" | xargs grep -l "setupPullWatchBlockPropsBasedSettings" 2>/dev/null

Repository: DiscourseGraphs/discourse-graph

Length of output: 59


🏁 Script executed:

#!/bin/bash
# Final check - search entire repo for any reference including comments
rg "setupPullWatchBlockPropsBasedSettings" --type ts -C 10

Repository: DiscourseGraphs/discourse-graph

Length of output: 1238


🏁 Script executed:

#!/bin/bash
# Check if there are any newer commits or branches that might use this function
git log --oneline --all -S "setupPullWatchBlockPropsBasedSettings" 2>/dev/null | head -20

Repository: DiscourseGraphs/discourse-graph

Length of output: 118


🏁 Script executed:

#!/bin/bash
# Check the git diff or status to see if this is a new file in this PR
git log --oneline --follow -- apps/roam/src/utils/pullWatchBlockPropsBasedSettings.ts 2>/dev/null | head -10

Repository: DiscourseGraphs/discourse-graph

Length of output: 118


🏁 Script executed:

#!/bin/bash
# Check the commit details to understand this PR better
git show 8f17d89 --stat

Repository: DiscourseGraphs/discourse-graph

Length of output: 40103


🏁 Script executed:

#!/an/bin/bash
# Check if the function is used in that commit or any subsequent commits
git show 8f17d89 --name-only

Repository: DiscourseGraphs/discourse-graph

Length of output: 29331


🏁 Script executed:

#!/bin/bash
# Check the full diff of that commit
git show 8f17d89

Repository: DiscourseGraphs/discourse-graph

Length of output: 50391


Critical: Add cleanup mechanism to prevent memory leaks when pull watch is registered.

The addPullWatch listener persists indefinitely without cleanup. Although this function is currently unused, it must provide a cleanup mechanism when called. Pattern in the codebase (e.g., useRoamStore.ts) shows the correct approach:

return () => {
  window.roamAlphaAPI.data.removePullWatch(
    "[:block/props]",
    `[:block/uid "${featureFlagsBlockUid}"]`,
    callback
  );
};

Additionally, the callback only logs to console—implement the actual settings update logic to complete this feature.

};