Skip to content

feat: ctx.data.staleWhileRevalidate() — host-owned stale-while-revalidate for extension views#46

Merged
pablopunk merged 3 commits into
mainfrom
feat/stale-while-revalidate-api
Jun 20, 2026
Merged

feat: ctx.data.staleWhileRevalidate() — host-owned stale-while-revalidate for extension views#46
pablopunk merged 3 commits into
mainfrom
feat/stale-while-revalidate-api

Conversation

@pablopunk

Copy link
Copy Markdown
Owner

What

Adds ctx.data.staleWhileRevalidate() — a synchronous host-owned stale-while-revalidate primitive for extension views. Extensions show cached items immediately with a subtle loading bar while fresh data loads in the background.

Before

Extensions had two bad options for data views:

  • Block until fetch completes → blank spinner every time
  • Manual caching + refresh → complex, brittle, no loading indicator when items exist

After

items: ctx.data.staleWhileRevalidate({
  cacheKey: 'my-data',
  loader: async () => { /* fetch and return items */ },
})
Cache state UX
Fresh (<60s) Items render instantly, no loader runs
Stale (60s–5min) Cached items + loading bar, background refresh
No cache Deferred spinner (same as loader())
Loader fails + stale cache Graceful fallback to stale items

Also fixed

The loading indicator was broken when items existed — isLoading only showed a spinner when items were empty. Added a subtle 2px animated gradient bar (.viewLoadingBar) that renders in list/grid views when both isLoading and items are present.

Changes (8 files, +389/-8)

  • src/electron/data-loader.ts — extended DataLoaderHandle, registry spawn() owns full S-W-R lifecycle
  • src/electron/main.ts — sync staleWhileRevalidate() API in extension context
  • src/electron/data-loader.test.ts — 5 new tests
  • src/resources/nevermind-extension-api.d.ts — API types + TSDoc
  • src/ui.tsxviewLoadingBar in ListView/GridView
  • src/styles.css — loading bar animation
  • src/App.tsx — hydrate respects payload.isLoading
  • src/preload-api.ts — widened ViewHydratePayload.isLoading

Validation

  • TypeScript: clean
  • Tests: 94/94 frontend pass (0 regressions)
  • All build checks pass

…validate for extension views

Extensions can now show cached items immediately with a subtle
loading bar while fresh data loads in the background.

- Synchronous API: returns a DataLoaderHandle, matches ctx.data.loader()
- Host-owned lifecycle: cache read/write/hydration in the loader registry
- Fresh cache (<ttlMs): items render instantly, no loader runs
- Stale cache (<staleTtlMs): cached items + loading bar, background refresh
- No cache: deferred spinner (same as loader())
- Loader failure + stale cache: graceful fallback to stale items
- New .viewLoadingBar: 2px animated gradient when isLoading && hasItems
- Hydrate contract: ViewHydratePayload.isLoading widened to boolean
- 5 new tests covering handle shape, stale hydrate, fresh skip, fallback
@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
nvm Ready Ready Preview, Comment Jun 20, 2026 12:48am

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@pablopunk, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 32 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ab1641ef-46e5-4d5f-8c06-efe32c63addd

📥 Commits

Reviewing files that changed from the base of the PR and between e6e140a and f152ba5.

📒 Files selected for processing (8)
  • src/App.tsx
  • src/electron/data-loader.test.ts
  • src/electron/data-loader.ts
  • src/electron/main.ts
  • src/preload-api.ts
  • src/resources/nevermind-extension-api.d.ts
  • src/styles.css
  • src/ui.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pablopunk
pablopunk merged commit 33d2b88 into main Jun 20, 2026
8 checks passed
@pablopunk
pablopunk deleted the feat/stale-while-revalidate-api branch June 20, 2026 00:53
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.

1 participant