Fix `requestAnimationFrame` not always being called when handling embeds

fixes/embed-requestAnimationFrame
Claire 2024-12-05 13:21:07 +01:00
parent 21f6780498
commit 50737ffe97
2 changed files with 11 additions and 11 deletions

View File

@ -62,13 +62,15 @@ window.addEventListener('message', (e) => {
// We use a timeout to allow for the React page to render before calculating the height // We use a timeout to allow for the React page to render before calculating the height
afterInitialRender(() => { afterInitialRender(() => {
window.parent.postMessage( window.requestAnimationFrame(() => {
{ window.parent.postMessage(
type: 'setHeight', {
id: data.id, type: 'setHeight',
height: document.getElementsByTagName('html')[0]?.scrollHeight, id: data.id,
}, height: document.getElementsByTagName('html')[0]?.scrollHeight,
'*', },
); '*',
);
});
}); });
}); });

View File

@ -24,9 +24,7 @@ export const useRenderSignal = () => {
renderSignalReceived = true; renderSignalReceived = true;
if (typeof onInitialRender !== 'undefined') { if (typeof onInitialRender !== 'undefined') {
window.requestAnimationFrame(() => { onInitialRender();
onInitialRender();
});
} }
}; };
}; };