ui: speed up env picker, by not re-fetching the environments list on mount#734
Merged
Conversation
The environment picker lives inside a modal that unmounts on close, so every open reset its state to null and re-showed a loading spinner for the debounce window. Cache the list in a module-level map seeded into initial state, filter client-side (no debounce), and clear the cache on sync. Claude <claude@anthropic.com>
Clear the cached environments whenever the selected project changes, so switching projects can't show the previous project's environments. Claude <claude@anthropic.com>
Copy the cached list into state on a cache hit (instead of returning) and guard the fetch with a cancelled flag, so the selector reflects the current project and stale in-flight fetches can't write. Drops the redundant clear-on-switch effect - the per-project cache is now read reactively. Claude <claude@anthropic.com>
… change Cache hits now run the same apply path as fetches (default source-environment selection) and clear the loading flag, and the list resets synchronously when projectKey changes so no stale frame renders. Closes the remaining selector edge cases. Claude <claude@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0773a6a. Configure here.
Gate the cache write on the cancelled flag so a fetch that resolves after unmount (e.g. after Sync clears the cache) can't rewrite it with pre-sync data. Claude <claude@anthropic.com>
… presentational The environment picker fetched and cached its own data while living in a modal that remounts, forcing it to hand-reconcile local state against a module cache, the projectKey prop, and in-flight fetches - the source of a whole run of staleness/loading/race bugs. FlagsPage already fetches environments, so hold them in its state and pass them down; EnvironmentSelector becomes presentational (search + list). Removes the module cache, effect, cancelled flag, and key reset. Claude <claude@anthropic.com>
nieblara
approved these changes
Jul 10, 2026
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.

Context
This is an easy UX win that's not related to the other dev server changes.
Problem
The environment picker refetched the environment list on each open, even when the data is unchanged:
environment_list_uncached.mov
Fix
Fetch environments once per project load:
environments_cached.mov
Testing
tsc,eslint,prettier, and the UI build pass;go build/go test ./internal/dev_server/...unchanged and green.defaultproject: reopening the picker no longer flashes; search filters instantly.Claude claude@anthropic.com
Note
Low Risk
Frontend-only caching and display logic with explicit invalidation on sync and project change; no auth or backend behavior changes.
Overview
Stops the project-settings environment picker from refetching and showing a loading state every time the dialog opens.
Environments are stored in a module-level cache keyed by project so data survives dialog unmounts. The UI loads the full list once per project on a cache miss (up to the existing
limit=1000API), and search filters in the browser viaEnvironmentSelectorinstead of hitting the network again. The cache is cleared when the user hits Sync or switches projects so lists can refresh when dev-server state changes.fetchEnvironmentsis centralized (e.g. inapi.ts) and wired fromFlagsPageintoProjectEditor/EnvironmentSelectoras props, so reopening settings reuses cached data rather than triggering a new fetch.Reviewed by Cursor Bugbot for commit e2c872c. Bugbot is set up for automated code reviews on this repo. Configure here.