Skip to content

Commit ab16de6

Browse files
committed
ENG-1716: Guard render effect against stale async continuation
The ensureChildren promise resolves asynchronously, so its .then callback could run after the effect's cleanup fired - re-registering a pull watch on a stale renderUid and stomping pullWatchArgsRef. Add a cancelled flag (same pattern as the buffer-lifecycle effect) so the continuation aborts after teardown.
1 parent cec980a commit ab16de6

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

apps/roam/src/components/settings/components/EphemeralBlocksPanel.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ const DualWriteBlocksPanel = ({
136136
const el = containerRef.current;
137137
if (!el || !renderUid) return;
138138

139+
let cancelled = false;
139140
const pattern = "[:block/string :block/order {:block/children ...}]";
140141
const entityId = `[:block/uid "${renderUid}"]`;
141142
const callback = () => handleChange();
@@ -158,6 +159,7 @@ const DualWriteBlocksPanel = ({
158159
).then(() => {});
159160

160161
void ensureChildren.then(() => {
162+
if (cancelled) return;
161163
el.innerHTML = "";
162164
void window.roamAlphaAPI.ui.components.renderBlock({
163165
uid: renderUid,
@@ -167,6 +169,7 @@ const DualWriteBlocksPanel = ({
167169
});
168170

169171
return () => {
172+
cancelled = true;
170173
window.clearTimeout(debounceRef.current);
171174
if (pullWatchArgsRef.current) {
172175
window.roamAlphaAPI.data.removePullWatch(...pullWatchArgsRef.current);

0 commit comments

Comments
 (0)