fix(env): drop the getBaseUrl browser-origin fallback - #6221
Conversation
The fallback was added in #6214 as a safety net while the real cause — the hosted env script losing its `beforeInteractive` strategy — was fixed in the same PR. With the injection ordering restored, `window.__ENV` is populated before hydration, so the fallback is unreachable in any correctly configured deployment. Guessing the origin was also unsafe in the one case it could still fire. An opaque origin — a sandboxed iframe, and `/chat/*` is deliberately embeddable — serializes to the string `'null'`, which is truthy, so `getBaseUrl()` would have returned `'null'` and every call site would have silently built `null/api/...`. A throw surfaces the misconfiguration instead of encoding it into request URLs. - restore the unconditional throw when NEXT_PUBLIC_APP_URL is unset or blank - mirror it back in the shared testing mock - flip the two fallback tests to assert the throw, keeping whitespace-only coverage Server-side behavior is unchanged: there was never a `window` to fall back to, so callers that already guard `getBaseUrl()` (`getBaseDomain`, `validateCallbackUrl`) keep their existing fail-closed paths.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview That removes a path where opaque origins (e.g. sandboxed embeds on Tests assert throws for missing env in jsdom, and Reviewed by Cursor Bugbot for commit ba89105. Configure here. |
Greptile SummaryRestores fail-fast URL configuration behavior by removing the browser-origin fallback from
Confidence Score: 5/5The PR appears safe to merge with no actionable defects identified. The root layout injects public environment values before browser hydration, server behavior remains fail-fast, and the shared testing environment supplies a valid default application URL.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/core/utils/urls.ts | Removes the browser-origin fallback and consistently throws when the public application URL is not configured. |
| apps/sim/lib/core/utils/urls.test.ts | Updates missing and whitespace-only environment cases to verify fail-fast behavior. |
| packages/testing/src/mocks/urls.mock.ts | Aligns the shared mock with production while retaining browser-origin behavior for the other mock helpers that still require it. |
Reviews (1): Last reviewed commit: "fix(env): drop the getBaseUrl browser-or..." | Re-trigger Greptile
Summary
window.location.originfallback ingetBaseUrl()was added in fix(env): restore beforeInteractive on the hosted public env script #6214 as a safety net while the real cause — the hosted env script losing itsbeforeInteractivestrategy — was fixed in the same PR. With injection ordering restored,window.__ENVis populated before hydration, so the fallback is unreachable in any correctly configured deployment./chat/*is deliberately embeddable (noX-Frame-Options) — serializes to the string'null', which is truthy.getBaseUrl()would have returned'null'and every call site would have silently builtnull/api/.... A throw surfaces the misconfiguration instead of encoding it into request URLs.Server-side behavior is unchanged. There was never a
windowto fall back to, so the server always threw. Callers that already guardgetBaseUrl()—getBaseDomain(), andvalidateCallbackUrl()via #6217 — keep their existing fail-closed paths untouched.Type of Change
Testing
Full
apps/simsuite: 18195 passed. The single failure isexecutor/handlers/pi/cloud-review-tools.test.ts, which shells out torgvia a pythonsubprocess— ripgrep is a shell function rather than a binary on my machine, so it is an environment artifact unrelated to these files.packages/testingsuite passes (39).tscclean,bun run lint:checkclean. Also ran the structural gates:check:boundaries,check:client-boundary,check:realtime-prune,check:tool-registry-boundary,check:react-query,check:utils,check:api-validation— all pass.Checklist