fix: ensure linkFailed event fires for 404, 500, and 403 errors in embeds (#25261)

- Add CalComPageStatus handling in NotFound and ErrorPage components using useLayoutEffect
- Remove redundant pageStatus logic from PageWrapperAppDir.tsx since App Router error/notFound pages set status themselves
- Refactor embed-iframe.ts: split checkPageStatusAndHandleError into hasPageError() and handlePageError()
- Add page status checks before firing linkReady to catch errors set after initialization
- Ensures linkFailed event fires correctly for all error status codes in embed scenarios

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Hariom BalharaandDevin AI authored and GitHub committed 2025-12-18 16:30:32 +00:00
1 parent 945ded951f
commit 71792bdeaa
4 files changed
+61 -36

No files matched your search

+41 -9
View File
@@ -414,6 +414,12 @@ export const methods = {
return;
}
// Check page status again before firing linkReady, in case it was set after initialization
if (hasPageError()) {
handlePageError(window.CalComPageStatus);
return;
}
makeBodyVisible();
log("renderState is 'completed'");
embedStore.renderState = "completed";
@@ -587,6 +593,29 @@ function main() {
}
}
/**
* Checks if there's a page error (non-200 status).
* @returns true if an error exists, false otherwise
*/
function hasPageError() {
const pageStatus = window.CalComPageStatus;
return !!(pageStatus && pageStatus != "200");
}
/**
* Handles a page error by firing the linkFailed event.
* @param pageStatus - The error status code (e.g., "404", "500", "403")
*/
function handlePageError(pageStatus: string) {
sdkActionManager?.fire("linkFailed", {
code: pageStatus,
msg: "Problem loading the link",
data: {
url: document.URL,
},
});
}
function initializeAndSetupEmbed() {
sdkActionManager?.fire("__iframeReady", {
isPrerendering: isPrerendering(),
@@ -604,16 +633,12 @@ function initializeAndSetupEmbed() {
// HACK
const pageStatus = window.CalComPageStatus;
if (!pageStatus || pageStatus == "200") {
if (hasPageError()) {
handlePageError(pageStatus);
return;
} else {
keepParentInformedAboutDimensionChanges({ embedStore });
} else
sdkActionManager?.fire("linkFailed", {
code: pageStatus,
msg: "Problem loading the link",
data: {
url: document.URL,
},
});
}
}
function runAllUiSetters(uiConfig: UiConfig) {
@@ -665,6 +690,13 @@ async function connectPreloadedEmbed({
runAsap(tryToFireLinkReady);
return;
}
// Check page status again before firing linkReady, in case it was set after initialization
if (hasPageError()) {
handlePageError(window.CalComPageStatus);
resolve();
return;
}
// link is ready now, so we could stop doing it.
// Also the page is visible to user now.
stopEnsuringQueryParamsInUrl();