Repository navigation
Keep app API requests out of the browser HTTP cache - #5095
Merged
Merged
Conversation
Chrome lets one in-flight request per URL own its HTTP cache entry; a second request for the same URL stalls up to 20 seconds waiting for it. App API GETs used the default cache mode, so a stuck request in another tab held up /api/v1/system/providers on reload and the sidebar provider icons appeared 20 seconds late. API responses are cached by React Query, so default app API requests to cache: "no-store" unless the caller picks a mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
File content routes answer with private, no-cache plus an ETag so the browser can revalidate unchanged files with a 304. The full-body file preview fetch opts back into the default cache mode so it keeps that revalidation instead of the app API no-store default. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Human comments
What was wrong
On reload, the sidebar's provider icons could take ~20 s to appear. A HAR from
ymichael.getbb.appshowedGET /api/v1/system/providers?spending 20,005 ms in Chrome's Stalled phase before it was sent, then 270 ms waiting on the server. It was the only stalled request out of 270 on the same HTTP/3 connection, and the server log shows no slow/system/providersrequests. The wait is Chrome's HTTP cache lock: only one in-flight request per URL may write the cache entry, and a second request for the same URL waits for it, up to a 20 s timeout. App API GETs used the default cache mode and the JSON responses have noCache-Control, so a stuck/system/providersrequest elsewhere in the browser profile (most likely another bb tab or the page being reloaded) held the lock.useProviders()returns an empty list until that request completes, so thread rows rendered without icons.What changed
apps/app/src/lib/app-surface.ts:appSurfaceRequestInitdefaults tocache: "no-store"unless the caller passes a cache mode. It is shared by the app SDK client, the plugin SDK client, the Hono API client and file previews, so these requests skip the HTTP cache and its lock. React Query, plus the localStorage copy for providers, already caches the JSON, so Chrome's HTTP cache added nothing for these requests.apps/app/src/lib/api.ts: the full-body file preview fetch passescache: "default". File content routes answer withprivate, no-cacheplus an ETag, and this keeps the browser revalidating unchanged files with a 304. That fetch can still hit the lock, as before. The partial first fetch in file previews was alreadyno-store.How you verified
GET /api/v1/system/providers?and got no response; the same request from tab B stalled 20,008 ms, and the stub received it only after the timeout. Withcache: "no-store"on tab B's fetch, the request took 1 ms.app-surface.test.ts: the default isno-storeand a caller's own cache mode is kept.pnpm exec turbo run typecheck lint test --filter=@bb/app: passes (lint 0 errors; 587 test files passed, 2 skipped).ymichael.getbb.appwith the fix deployed.🤖 Generated with Claude Code