Skip to content

Commit b9e5f91

Browse files
committed
Add room ID generation for Cloudflare sync in Tldraw components
- Introduced `getSyncRoomId` function to create a unique room ID based on the page UID and graph name. - Updated `useCloudflareSyncStore` to utilize the new room ID for WebSocket connections. - Added comments in `Tldraw.tsx` to clarify canvas identity handling in Roam.
1 parent 803c475 commit b9e5f91

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ export const isPageUid = (uid: string) =>
149149
];
150150

151151
const TldrawCanvas = ({ title }: { title: string }) => {
152+
// In Roam, canvas identity is currently keyed by the page UID.
153+
// Room sync is graphName/uid
152154
const pageUid = useMemo(() => getPageUidByPageTitle(title), [title]);
153155
const useCloudflareSync =
154156
TLDRAW_CLOUDFLARE_SYNC_ENABLED &&

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export type CloudflareCanvasStoreAdapterResult = {
2222
isLoading: boolean;
2323
};
2424

25+
const getSyncRoomId = ({ pageUid }: { pageUid: string }): string => {
26+
const graphName = window.roamAlphaAPI.graph.name;
27+
return `${graphName}/${pageUid}`;
28+
};
29+
2530
const parseRoamUploadResponse = (value: string): string => {
2631
return value.replace(/^!\[\]\(/, "").replace(/\)$/, "");
2732
};
@@ -63,14 +68,15 @@ export const useCloudflareSyncStore = ({
6368
);
6469

6570
const uri = useMemo(() => {
71+
const roomId = encodeURIComponent(getSyncRoomId({ pageUid }));
6672
const query = new URLSearchParams();
6773
for (const shapeType of customShapeTypes) {
6874
query.append("shapeType", shapeType);
6975
}
7076
for (const bindingType of customBindingTypes) {
7177
query.append("bindingType", bindingType);
7278
}
73-
return `${TLDRAW_CLOUDFLARE_SYNC_WS_BASE_URL}/connect/${pageUid}?${query.toString()}`;
79+
return `${TLDRAW_CLOUDFLARE_SYNC_WS_BASE_URL}/connect/${roomId}?${query.toString()}`;
7480
}, [customShapeTypes, customBindingTypes, pageUid]);
7581

7682
const store = useSync({

0 commit comments

Comments
 (0)