Skip to content

Commit 5d356b1

Browse files
Update InteractiveAtomMessenger.importable.tsx
1 parent 9db6ade commit 5d356b1

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

dotcom-rendering/src/components/InteractiveAtomMessenger.importable.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,27 @@ export const InteractiveAtomMessenger = ({ id }: Props) => {
4444
);
4545

4646
useEffect(() => {
47-
const found = document.querySelector<HTMLIFrameElement>(
48-
`iframe[id="${id}"]`,
49-
);
50-
if (!found) return;
47+
let cancelled = false;
5148

52-
setIframe(found);
49+
const check = () => {
50+
if (cancelled) return;
51+
52+
const found = document.querySelector<HTMLIFrameElement>(
53+
`iframe[id="${id}"]`,
54+
);
55+
56+
if (found) {
57+
setIframe(found);
58+
} else {
59+
requestAnimationFrame(check);
60+
}
61+
};
62+
63+
check();
64+
65+
return () => {
66+
cancelled = true;
67+
};
5368
}, [id]);
5469

5570
useEffect(() => {

0 commit comments

Comments
 (0)