fix: guard VITE_BACKEND_URL fallback to prevent module-load crash - #675
Merged
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Saelmala
approved these changes
Aug 26, 2026
birme
commented
Aug 27, 2026
birme
left a comment
Contributor
Author
There was a problem hiding this comment.
Code Review
Verdict: LGTM
Summary: A small, correct fix for a real module-load crash (#646). The root cause — calling .replace() on a possibly-undefined import.meta.env.VITE_BACKEND_URL before the || fallback could short-circuit — is properly addressed by moving the fallback inside the expression with ??. A focused regression test is included and CI is fully green.
Blocking
None.
Warnings
None.
Suggestions
src/api/api.ts:4-6— The fix is correct:(import.meta.env.VITE_BACKEND_URL ?? window.location.origin).replace(/\/+$/, "")now resolves the fallback before.replace()runs, which is exactly why the old... || window.location.originform failed (theTypeErrorwas thrown inside the template literal before||was evaluated). Consider a brief inline comment noting why??must wrap the value pre-.replace(), to prevent a future refactor from reintroducing the crash. Optional.src/api/api.test.ts:17—vi.stubEnv("VITE_BACKEND_URL", undefined)correctly reproduces the unset-at-build-time path and would fail against the old code with the originalTypeError, so the regression test genuinely guards the fixed behavior. As an optional strengthening, you could also assert on the resolvedAPIURL shape (e.g., that it starts withwindow.location.originand ends with the API version) rather than only that the import resolves — this would catch a regression where the module loads but resolves to a wrong/undefined-prefixed URL.src/api/api.test.ts— Test uses the defaulthappy-domenvironment (no@vitest-environment jsdomoverride), touches noRTCPeerConnection/srcObject, and uses nosetTimeout-based waits — all consistent with project test rules. No action needed.
Domain Note
Not applicable — this change is confined to base-URL resolution and does not touch audio routing, PTT, dominant speaker, data channel parsing, or WHIP/WHEP session lifecycle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/api/api.tscalled.replace()directly onimport.meta.env.VITE_BACKEND_URL; when that env var is undefined at build time this threw aTypeErrorduring module evaluation, crashing the whole app at load.|| window.location.originfallback never ran because the crash happened inside the template-literal evaluation before||was reached.??sowindow.location.originis used before.replace()is called:${(import.meta.env.VITE_BACKEND_URL ?? window.location.origin).replace(/\/+$/, "")}/${API_VERSION}.VITE_BACKEND_URLas undefined and asserts the module loads without throwing (fails on old code with the exactTypeError, passes on the fix).Test plan
npm test) — 18 files, 147 testsnpm run typecheck)npm run lint)Closes #646
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com