Skip to content

Block QueryClient API surface in UI #8530

@MajorLift

Description

@MajorLift

File: packages/react-data-query/src/createUIQueryClient.ts
Size: M | Hours: 6–10


Problem

Under ADR 0020 Option A, the messenger-routed proxy queryFn (createUIQueryClient.ts:64-82) and OmitKeyof wrapper hooks enforce that the background owns data-service-keyed cache entries. Neither mechanism covers the QueryClient instance surface. UI code with a handle on queryClient (via ui/contexts/query-client.ts or useQueryClient()) can call instance methods that bypass the proxy or cross the ownership boundary without warning.

Currently dormant (DATA_SERVICES = []). Becomes live on first data-service registration.


Solution

Mirror the existing invalidateQueries shadow at createUIQueryClient.ts:145-168. For each method below, shadow on the returned client and throw a descriptive error if the query key matches a registered data-service prefix. Non-data-service keys pass through unchanged.

Methods to guard:

  • setQueryDefaults — per-key cache-policy override; ADR 0020:307-316 moves cache policy to the service layer
  • setMutationDefaults — no data-service mutations today; block preemptively
  • setDefaultOptions — block only when options.queries.queryFn is set
  • prefetchQuery / prefetchInfiniteQuery — pending policy decision on whether UI-side prefetch is in scope; block until decided
  • fetchQuery / fetchInfiniteQuery — same
  • setQueryData / setQueriesData — block; replacement implementation tracked separately (see Dependencies)
  • ensureQueryData / ensureInfiniteQueryData — block; replacement implementation tracked separately (see Dependencies)

Acceptance Criteria

  • All methods above throw on data-service keys with a descriptive error citing the data service as cache owner and referencing ADR 0020
  • setDefaultOptions only throws when options.queries.queryFn is set; other client-wide tuning unaffected
  • Non-data-service keys pass through for all methods (Option C hooks unaffected)
  • invalidateQueries shadow, wrapper hooks, and hydrate-based cache-sync continue to work
  • Unit tests per method: data-service key throws, non-data-service key passes, error message correct
  • Regression tests for Option C consumers (useHistoricalPrices, activity-v2/hooks, useMerklRewards) still pass

Dependencies

Depends on: MetaMask/metamask-extension#41183 (merged)
Dependents: MetaMask/metamask-extension#41977
Follow-up epic (Layer 2 + replacements): #8531

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions