perf(detail): react.cache Copilot calls + skip client refire#1215
Conversation
Per-request memoization deduplicates Copilot API calls within a single RSC / route handler invocation. Validated in measurement: 4 call sites of getInternalUser(self) collapsed to 1 actual network fetch on the detail page. Falls back to no-op outside a request context (CLI scripts, Trigger.dev jobs) so unrelated code paths are unaffected. Cache key includes the optional customApiKey so workspace-key-override calls don't collide.
When set, seeds SWR with the SSR-rendered initialTask and disables
revalidateOnMount, eliminating the redundant client-side refire of
/api/tasks/{id} after hydration. Caller opts in via the new prop; the
default behavior is unchanged so existing call sites continue to
revalidate as before.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…s-app into anit/out-3701-optimize-task-detail-page
|
Deployment failed with the following error: Learn More: https://vercel.link/multiple-function-regions |
Greptile SummaryThis PR introduces two low-risk performance foundations for the detail-page work:
Confidence Score: 5/5Safe to merge — both changes are additive and opt-in, with no modification to existing call paths for non-fallback consumers. The react.cache wrappers are purely additive: wrapWithRetry is still used for every other method, and the two rewired methods delegate to the same underlying _ functions via the same withRetry budget. The useFallback prop defaults to undefined/falsy, leaving the existing SWR behaviour fully intact for all current call sites. The proactive mutate in the effect correctly addresses the revisit-stale-cache edge case raised in the prior review thread. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant RSC as RSC (detail page)
participant CA as CopilotAPI
participant Cache as react.cache
participant Copilot as Copilot Network
RSC->>CA: getInternalUser("self") [call site 1]
CA->>Cache: cachedFetchInternalUser(token, key, "self")
Cache->>Copilot: _getInternalUser("self") + withRetry
Copilot-->>Cache: InternalUsers
Cache-->>CA: cached result
CA-->>RSC: InternalUsers
RSC->>CA: getInternalUser("self") [call site 2]
CA->>Cache: cachedFetchInternalUser(token, key, "self")
Cache-->>CA: memoized (no network call)
CA-->>RSC: InternalUsers
RSC->>CA: getWorkspace() [call site 1]
CA->>Cache: cachedFetchWorkspace(token, key)
Cache->>Copilot: _getWorkspace() + withRetry
Copilot-->>Cache: WorkspaceResponse
Cache-->>CA: cached result
CA-->>RSC: WorkspaceResponse
RSC->>CA: getWorkspace() [call site 2]
CA->>Cache: cachedFetchWorkspace(token, key)
Cache-->>CA: memoized (no network call)
CA-->>RSC: WorkspaceResponse
Reviews (2): Last reviewed commit: "fix(detail): seed SWR cache with fresh i..." | Re-trigger Greptile |
Without this, a stale SWR cache entry from an earlier visit beats the fresh SSR render: fallbackData only applies when cache is empty, and revalidateOnMount: false suppresses the refetch. Mutate the cache with initialTask on mount so the latest SSR data wins.
|
@greptileai review the PR again. regarding the cache memoizing the error. If it throws error even after 3 retries then we already have an issue. So That is expected. |
The only call site (detail page) never passed useFallback, so the fallbackData + revalidateOnMount: false branch and the mutate-on-mount seed effect were dead code. Removing them also drops the stale SWR cache concern, since SWR now revalidates on mount as normal.
Ref: OUT-3701
Foundation for the detail-page perf work. Two low-risk changes that the deeper refactor in the stacked PR builds on.
Changes
CopilotAPI— wrapgetInternalUser+getWorkspaceinreact.cache. Per-request memoization deduplicates Copilot calls within a single RSC / route handler invocation. Falls back to no-op in non-request contexts (jobs, CLI).OneTaskDataFetcher— newuseFallbackprop that seeds SWR with the SSR-rendered task and disablesrevalidateOnMount. Default behavior unchanged; the detail page opts in via the stacked PR.Measured impact
Validated dedup: 4 call sites of
getInternalUser(self)collapse to 1 actual network fetch on a typical detail-page load.Test plan
Stacked PR
The actual page handler refactor lives in #1214 (against this branch).
🤖 Generated with Claude Code