Skip to content

Protect against some previewing errors I noticed this morning#1333

Open
KevinDCarlson wants to merge 1 commit into
mainfrom
kdc-preview-fixes
Open

Protect against some previewing errors I noticed this morning#1333
KevinDCarlson wants to merge 1 commit into
mainfrom
kdc-preview-fixes

Conversation

@KevinDCarlson

@KevinDCarlson KevinDCarlson commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

The problem this was responsive to is that it was possible to get a Netlify preview up that was totally incapable of opening a model, if you have a stale session from the same host, due to some interactions with Firebase attempting to do some auth that it can't do on a non-whitelisted host. It's a bit hard to repro the bug situation itself because it happens entirely client-side, but the changes here are pretty chill. The time-outs should never happen on the happy path.

headers,
};
try {
const token = await withTimeout(currentUser.getIdToken(), 5000);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can sometimes hang forever if there's a stale session in the browser and your current domain isn't Firebase-authorized, i.e. if you're futzing around a lot in Netlify previews.

@kasbah kasbah Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "futzing around"? You tried to login via Google/Github on the preview?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think you have to have tried to log in to make this break, it's something about the mere request for a firebase token that then gets turned down. I wouldn't be able to fully diagnose it myself but I could send you some robot's description if you like.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is what the robot says:

Symptom: On the sirius Netlify branch preview (branch-sirius--catcolab.netlify.app, built in staging → backend-next + Firebase project catcolab-next), any backend call hung forever — "creating…" spinner never resolved, import silently reset, zero RPC requests in the Network tab, nothing logged. Incognito worked fine.

Root cause: The frontend attaches auth per-request in createFetchWithAuth (packages/frontend/src/api/rpc.ts):

if (currentUser) {
    const token = await currentUser.getIdToken();  // <-- stalls, never settles
    headers.set("Authorization", `Bearer ${token}`);
}
return await fetch(...);   // never reached

currentUser.getIdToken() never resolved, so the fetch was never dispatched. It stalls because the preview origin isn't in catcolab-next's Authorized domains, and Firebase's token-refresh path coordinates through the cross-origin gapi iframe hosted at the authDomain — on an unauthorized origin that handshake never posts back (it doesn't error, it just hangs).

@KevinDCarlson KevinDCarlson Jul 9, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we're confused about how currentUser could ever have gotten to be non-null on a non-Firebase-whitelisted domain, and the forensics trail is cold. But the incognito check seems to prove that's what somehow happened. Might be some deeper mystery in here, but cutting off these infinite hangs does at least fix the symptom. Or, if this is ever observed again, whitelisting that preview on Firebase also fixes it. Sorry I can't actually explain how it happened.

@epatters

epatters commented Jul 7, 2026

Copy link
Copy Markdown
Member

Thanks Kevin! @kasbah, can you please review whether this is the right approach to solve this?

@epatters epatters requested review from kasbah and removed request for epatters July 7, 2026 23:15
@epatters epatters added bug Something isn't working frontend TypeScript frontend and Rust-wasm integrations labels Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working frontend TypeScript frontend and Rust-wasm integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants