Skip to content

Commit e4ff23e

Browse files
sid597mdroidian
andauthored
ENG-1266: Bug: Component not loading on any page (#681)
* findDiscourseNode accepts title as well * Refactor findDiscourseNode to ensure uid is always a string and update related components to handle uid correctly. This improves type safety and prevents potential undefined errors. * . --------- Co-authored-by: Michael Gartner <[email protected]>
1 parent 373c15f commit e4ff23e

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

apps/roam/src/components/canvas/Tldraw.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ const TldrawCanvas = ({ title }: { title: string }) => {
479479
? { x: lastTime.x + w * 0.025, y: lastTime.y + h * 0.05 }
480480
: { x: x - DEFAULT_WIDTH / 2, y: y - DEFAULT_HEIGHT / 2 };
481481
const nodeType = findDiscourseNode({
482-
uid: e.detail.uid,
482+
uid: e.detail.uid || "",
483483
nodes: allNodes,
484484
});
485485
if (nodeType) {

apps/roam/src/utils/findDiscourseNode.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@ const findDiscourseNode = ({
88
title,
99
nodes = getDiscourseNodes(),
1010
}: {
11-
uid?: string;
11+
uid: string;
1212
title?: string;
1313
nodes?: DiscourseNode[];
1414
}): DiscourseNode | false => {
15-
if (uid === undefined) return false;
1615
if (typeof discourseNodeTypeCache[uid] !== "undefined") {
1716
return discourseNodeTypeCache[uid];
1817
}
1918

2019
const matchingNode =
2120
nodes.find((node) =>
2221
title === undefined
23-
? matchDiscourseNode({ ...node, uid: uid })
22+
? matchDiscourseNode({ ...node, uid })
2423
: matchDiscourseNode({ ...node, title }),
2524
) || false;
2625
discourseNodeTypeCache[uid] = matchingNode;

apps/roam/src/utils/formatUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const getReferencedNodeInFormat = ({
136136
}) => {
137137
let format = providedFormat;
138138
if (!format) {
139-
const discourseNode = findDiscourseNode({ uid });
139+
const discourseNode = findDiscourseNode({ uid: uid || "" });
140140
if (discourseNode) format = discourseNode.format;
141141
}
142142
if (!format) return null;

apps/roam/src/utils/initializeObserversAndListeners.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ export const initObservers = async ({
9595
text: "(BETA) Suggestive Mode Enabled",
9696
}).value;
9797

98-
const nodes = getDiscourseNodes();
99-
const node = findDiscourseNode({ title, nodes });
98+
const uid = getPageUidByPageTitle(title);
99+
const node = findDiscourseNode({ uid, title });
100100
const isDiscourseNode = node && node.backedBy !== "default";
101101
if (isDiscourseNode) {
102-
const uid = getPageUidByPageTitle(title);
103102
if (isSuggestiveModeEnabled) {
104103
renderPossibleDuplicates(h1, title, node);
105104
}

0 commit comments

Comments
 (0)