Skip to content

ui: speed up env picker, by not re-fetching the environments list on mount#734

Merged
davidbrackbill merged 6 commits into
mainfrom
feat/cache-environments
Jul 10, 2026
Merged

ui: speed up env picker, by not re-fetching the environments list on mount#734
davidbrackbill merged 6 commits into
mainfrom
feat/cache-environments

Conversation

@davidbrackbill

@davidbrackbill davidbrackbill commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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
  • Hoist environments into FlagsPage state (from the fetch it already does on project load) and pass them down through ProjectEditor.
  • EnvironmentSelector becomes presentational — search box + client-side filtering, no fetch/cache/effect.
  • The full list is fetched once per project (client filters); no debounce, no per-keystroke round-trips.

Testing

  • tsc, eslint, prettier, and the UI build pass; go build/go test ./internal/dev_server/... unchanged and green.
  • Verified live against the Catamorphic default project: 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=1000 API), and search filters in the browser via EnvironmentSelector instead 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.

fetchEnvironments is centralized (e.g. in api.ts) and wired from FlagsPage into ProjectEditor / EnvironmentSelector as 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.

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>
Comment thread internal/dev_server/ui/src/EnvironmentSelector.tsx Outdated
Clear the cached environments whenever the selected project changes, so
switching projects can't show the previous project's environments.

Claude <claude@anthropic.com>
Comment thread internal/dev_server/ui/src/EnvironmentSelector.tsx Outdated
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>
Comment thread internal/dev_server/ui/src/EnvironmentSelector.tsx Outdated
Comment thread internal/dev_server/ui/src/EnvironmentSelector.tsx Outdated
Comment thread internal/dev_server/ui/src/EnvironmentSelector.tsx Outdated
… 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>

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread internal/dev_server/ui/src/EnvironmentSelector.tsx Outdated
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>
@davidbrackbill davidbrackbill changed the title dev-server: cache environments in the UI to stop the reopen flash ui: speed up env picker, by not re-rendering the environments list with a new fetch Jul 9, 2026
@davidbrackbill davidbrackbill requested a review from nieblara July 9, 2026 17:35
@davidbrackbill davidbrackbill marked this pull request as ready for review July 9, 2026 17:35
@davidbrackbill davidbrackbill changed the title ui: speed up env picker, by not re-rendering the environments list with a new fetch ui: speed up env picker, by not re-fetching the environments list on mount Jul 9, 2026
@davidbrackbill davidbrackbill requested a review from cspath1 July 10, 2026 14:32
@davidbrackbill davidbrackbill merged commit 2278ad0 into main Jul 10, 2026
8 checks passed
@davidbrackbill davidbrackbill deleted the feat/cache-environments branch July 10, 2026 15:16
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