Skip to content

Commit 856d223

Browse files
fix: Use setTimeout instead of requestAnimationFrame which is more reliable and support calOrigin in prerender calcom#21205 (calcom#21730)
1 parent ad69736 commit 856d223

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

packages/embeds/embed-core/src/embed-iframe.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const embedStore = {
102102
// Avoid unnecessary history push
103103
window.history.replaceState({}, "", currentUrl.toString());
104104
}
105-
requestAnimationFrame(updateIfNeeded);
105+
runAsap(updateIfNeeded);
106106
return {
107107
hasChanged,
108108
};
@@ -167,11 +167,8 @@ if (isBrowser) {
167167
}
168168

169169
function runAsap(fn: (...arg: unknown[]) => void) {
170-
if (isSafariBrowser) {
171-
// https://adpiler.com/blog/the-full-solution-why-do-animations-run-slower-in-safari/
172-
return setTimeout(fn, 50);
173-
}
174-
return requestAnimationFrame(fn);
170+
// We don't use rAF because it runs slower in Safari plus doesn't run if the iframe is hidden sometimes
171+
return setTimeout(fn, 50);
175172
}
176173

177174
function log(...args: unknown[]) {

packages/embeds/embed-core/src/embed.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,13 +1159,15 @@ class CalApi {
11591159
type,
11601160
options = {},
11611161
pageType,
1162+
calOrigin,
11621163
}: {
11631164
calLink: string;
11641165
type?: "modal" | "floatingButton";
11651166
options?: {
11661167
prerenderIframe?: boolean;
11671168
};
11681169
pageType?: EmbedPageType;
1170+
calOrigin?: string;
11691171
}) {
11701172
// eslint-disable-next-line prefer-rest-params
11711173
validate(arguments[0], {
@@ -1210,7 +1212,7 @@ class CalApi {
12101212
this.cal.isPrerendering = true;
12111213
this.modal({
12121214
calLink,
1213-
calOrigin: config.calOrigin,
1215+
calOrigin: calOrigin || config.calOrigin,
12141216
__prerender: true,
12151217
...(pageType ? { config: { "cal.embed.pageType": pageType } } : {}),
12161218
});
@@ -1227,15 +1229,18 @@ class CalApi {
12271229
calLink,
12281230
type,
12291231
pageType,
1232+
calOrigin,
12301233
}: {
12311234
calLink: string;
12321235
type: "modal" | "floatingButton";
12331236
pageType?: EmbedPageType;
1237+
calOrigin?: string;
12341238
}) {
12351239
this.preload({
12361240
calLink,
12371241
type,
12381242
pageType,
1243+
calOrigin,
12391244
});
12401245
}
12411246

0 commit comments

Comments
 (0)