Skip to content

ix: Fix rece condition when detecting the browser extension.#24

Merged
RickyNotaro merged 1 commit into
masterfrom
feat/firefox-extension-compat
Mar 25, 2026
Merged

ix: Fix rece condition when detecting the browser extension.#24
RickyNotaro merged 1 commit into
masterfrom
feat/firefox-extension-compat

Conversation

@RickyNotaro

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings March 25, 2026 02:40
@RickyNotaro
RickyNotaro merged commit 1971759 into master Mar 25, 2026
4 of 5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a race condition in production where API requests could be routed through the proxy fallback before the browser extension detection finished, by making requests wait for a single shared detection promise.

Changes:

  • Replace per-call extension detection with a module-level detectionPromise that runs once in production.
  • Make the production Axios request interceptor async and await extension detection before choosing direct vs corsproxy.io routing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/http-common.ts
Comment on lines +13 to +22
try {
const resp = await fetch(
`${TARGET_BASE}/WCF/LSI/LSIBookingServiceV3.svc/GetAvailableVehicles?BranchID=1&LanguageID=2`,
{ method: 'HEAD', mode: 'cors' },
);
extensionDetected = resp.ok;
} catch {
extensionDetected = false;
}
detectionDone = true;

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

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

fetch() can hang for a long time on some networks; since all production requests now await detectionPromise, this can stall every API call indefinitely. Consider adding an explicit timeout/AbortController (and treating timeout as “no extension”) so requests can proceed via the proxy fallback even if detection never completes.

Suggested change
try {
const resp = await fetch(
`${TARGET_BASE}/WCF/LSI/LSIBookingServiceV3.svc/GetAvailableVehicles?BranchID=1&LanguageID=2`,
{ method: 'HEAD', mode: 'cors' },
);
extensionDetected = resp.ok;
} catch {
extensionDetected = false;
}
detectionDone = true;
// Ensure extension detection cannot hang indefinitely; treat timeout as "no extension".
if (typeof AbortController === 'undefined') {
// Fallback for environments without AbortController: behave as before (no explicit timeout).
try {
const resp = await fetch(
`${TARGET_BASE}/WCF/LSI/LSIBookingServiceV3.svc/GetAvailableVehicles?BranchID=1&LanguageID=2`,
{ method: 'HEAD', mode: 'cors' },
);
extensionDetected = resp.ok;
} catch {
extensionDetected = false;
}
detectionDone = true;
return;
}
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
try {
const resp = await fetch(
`${TARGET_BASE}/WCF/LSI/LSIBookingServiceV3.svc/GetAvailableVehicles?BranchID=1&LanguageID=2`,
{ method: 'HEAD', mode: 'cors', signal: controller.signal },
);
extensionDetected = resp.ok;
} catch {
// Network errors or aborts (including timeout) are treated as "no extension".
extensionDetected = false;
} finally {
clearTimeout(timeoutId);
detectionDone = true;
}

Copilot uses AI. Check for mistakes.
Comment thread src/http-common.ts
Comment on lines +11 to +13
const detectionPromise = !import.meta.env.DEV
? (async () => {
try {

Copilot AI Mar 25, 2026

Copy link

Choose a reason for hiding this comment

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

detectionPromise resolves to void and updates module-level state (extensionDetected/detectionDone). This makes it harder to reason about and requires the extra detectionDone flag. Consider making the promise resolve to the detected boolean (and/or always awaiting the same promise) to reduce shared mutable state and simplify the interceptor logic.

Copilot uses AI. Check for mistakes.
@RickyNotaro
RickyNotaro deleted the feat/firefox-extension-compat branch March 30, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants