Skip to content

Guard getApiOrigin against undefined VITE_API#3332

Merged
rossnelson merged 1 commit into
mainfrom
com-80-get-api-origin-undefined
Apr 22, 2026
Merged

Guard getApiOrigin against undefined VITE_API#3332
rossnelson merged 1 commit into
mainfrom
com-80-get-api-origin-undefined

Conversation

@rossnelson

@rossnelson rossnelson commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements - Refreshing worker deployment versioning page throws error

On page refresh, the load function calls fetchDeployment()routeForApi()base()getApiOrigin(). During load, neither page.data?.webUrl nor globalThis.AppConfig.apiUrl is available, so base() falls through to getApiOrigin(). There, import.meta.env.VITE_API is undefined in cloud-ui consumer environments, causing TypeError: Cannot read properties of undefined (reading 'startsWith').

Fix: add if (endpoint === undefined) return null; guard before the startsWith call. Uses strict equality (not !endpoint) to preserve the existing behaviour when VITE_API is an empty string.

Test plan

  • New unit test: should return null when VITE_API is undefined — verifies no throw and null return
  • Existing tests all pass (pnpm test -- --run: 137 files, 1798 tests)
  • pnpm lint clean
  • pnpm check no new errors
  • pnpm build:server succeeds

Refreshing the worker deployment versioning page in cloud-ui SSR
threw TypeError because VITE_API is undefined in that environment
and getApiOrigin called .startsWith on it.

Return null early when VITE_API is undefined so base() produces an
empty string and routeForApi produces a relative URL that
SvelteKit's server-side fetch resolves correctly.

Fixes COM-80
@vercel

vercel Bot commented Apr 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
holocene Ready Ready Preview, Comment Apr 21, 2026 8:15pm

Request Review

@rossnelson
rossnelson marked this pull request as ready for review April 21, 2026 20:21
@rossnelson
rossnelson requested a review from a team as a code owner April 21, 2026 20:21
@rossnelson
rossnelson requested a review from GiantRobots April 21, 2026 20:22
@rossnelson rossnelson changed the title [COM-80] fix(ui): guard getApiOrigin against undefined VITE_API Guard getApiOrigin against undefined VITE_API Apr 21, 2026
@rossnelson
rossnelson merged commit 39c41d2 into main Apr 22, 2026
20 checks passed
@rossnelson
rossnelson deleted the com-80-get-api-origin-undefined branch April 22, 2026 14:07
rossedfort added a commit that referenced this pull request Apr 22, 2026
Auto-generated version bump from 2.48.4 to 2.49.0

Bump type: minor

Changes included:
- [`9146199f`](9146199) fix: ref main in reusable PR review workflows (#3326)
- [`ca904926`](ca90492) test(e2e): add end-to-end payload decoder coverage (#3321)
- [`4e32d230`](4e32d23) chore: add setup-worktree skill (#3278)
- [`a789fbdb`](a789fbd) Fix decoding payloads for user metadata (#3328)
- [`21f2d448`](21f2d44) ci: remove unused Set up Protoc step from workflows (#3323)
- [`39c41d25`](39c41d2) fix(ui): guard getApiOrigin against undefined VITE_API (#3332)
- [`627cbb1b`](627cbb1) feat: add showInstancesLink prop to deployment header (#3331)
- [`0726c65e`](0726c65) Check certFile modification time instead of keyFile (#3178)
- [`8c79931b`](8c79931) feat(DT-3887): remove Dispatch Rate Epsilon from compute scaling UI (#3334)

Co-authored-by: rossedfort <[email protected]>
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