Skip to content

fix(rpc): honor automatic client caching - #430

Draft
SaKaNa-Y wants to merge 1 commit into
devframes:mainfrom
SaKaNa-Y:fix/automatic-rpc-cache
Draft

SaKaNa-Y wants to merge 1 commit into
devframes:mainfrom
SaKaNa-Y:fix/automatic-rpc-cache

Conversation

@SaKaNa-Y

@SaKaNa-Y SaKaNa-Y commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Important

Please take a moment to read this. Thank you!

I should include a brief explanation of the problem in my own words in every PR. If that explanation is missing, please @mention me and do not merge this PR until I have added it. You may also leave this PR unaddressed (because this means I have not fulfilled my responsibilities as the author).

If my explanation is unclear or difficult to follow, please ask me to clarify or provide reproduction steps or supporting evidence.

I welcome suggestions and counterarguments, especially questions about anything I may have overlooked. (Your feedback helps me learn and improve. 🙏)

I hold myself to this standard for every PR, regardless of its size.

Summary

Calling a static RPC or a query marked cacheable: true with connectDevframe({ cacheOptions: true }) sends every request to the server, including repeated arguments. The client starts with an empty cache function list and never fills it, so the documented option has no effect.

Read eligible method names through an authenticated RPC endpoint before using automatic caching. Cache static methods and queries that opt in; keep actions and events running. Preserve explicit function lists and custom serializers, and fall back to normal RPC calls when an older server has no discovery endpoint.

cacheOptions: true
  read eligible methods → cache responses by arguments
  invalidate / declarations change / connection changes → clear cache

Add a cache invalidation broadcast that hosts can send after changing data. Registration and updates also invalidate the cache and refresh eligibility. Ignore responses that arrive after invalidation when writing cache entries, and clear cached data on trust changes and close. Update the guide, event reference, and API snapshots.

Evidence

  • Before: On the base commit, the new WebSocket and SSE regression tests both fail: inputs 1, 1, 2 execute static and cacheable query handlers 3 times.
    After: Both execute 2 times. Uncached queries, actions, and events still execute 3 times.
  • 18 new tests cover both transports, falsy values, explicit lists, custom serializers, disabled caching, rejected calls, older servers, dynamic declarations, invalidation during a pending request, trust revocation, and close.
  • pnpm lint, pnpm knip, pnpm typecheck, and pnpm build pass.
  • pnpm test --run: 148 files pass; 1657 tests pass and 13 are skipped.
  • A separate smoke test imports the built dist modules and confirms the expected handler counts over real WebSocket and SSE connections.

Merge Danger

Door: Two-way; this change can be reverted.

Blast Radius: RPC caching. Automatic caching adds one discovery request per cache generation. Invalidation clears all cached methods; hosts must broadcast it after changing data read by cached queries.

Discover cacheable methods from server declarations and invalidate client caches when declarations or connection state change. Preserve explicit cache options and reject stale in-flight cache writes.
@vercel

vercel Bot commented Oct 5, 2026

Copy link
Copy Markdown

@SaKaNa-Y is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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