Block `QueryClient` API surface in UI
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- typescript
调研方向
从 packages/react-data-query/src/createUIQueryClient.ts 开始,阅读现有的 invalidateQueries 和 defaultMutationOptions shadow 以及 wrapper hooks。确定按调用进行的 queryFn 和 mutationFn override 应如何工作,然后为列出的 QueryClient 方法添加 guard,同时保留非数据服务的 key。为每个方法添加针对抛出和透传行为的单元测试,以及指定的 Option C 回归测试。
由索引模型根据 Issue 内容生成。
描述
File: packages/react-data-query/src/createUIQueryClient.ts
Size: M | Hours: 6–10
Problem
Under ADR 0020 Option A, two messenger-routed proxies and the OmitKeyof wrapper hooks enforce that the background owns data-service-keyed cache entries: the proxy queryFn, and since #9324 (Update BaseDataService to accommodate mutations) the defaultMutationOptions shadow that injects a mutationFn. None of them 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.
No longer dormant. DATA_SERVICES on metamask-extension main holds MoneyAccountBalanceService and MoneyAccountApiDataService, so the guards below are on a live path rather than a preemptive one.
The options-resolution path is a second surface
Every method below is a QueryClient instance method. A shadow on the instance cannot reach a bypass supplied through per-call options, and both proxies can be overridden that way:
queryFn— the proxy is a client default, so an explicitqueryFnon auseQuerycall wins.OmitKeyofstrips it from the wrapper's type, which is a compile-time strip with no runtime check.mutationFn—defaultedOptions.mutationFn ??=is a nullish-assign, so a caller-suppliedmutationFnon a data-servicemutationKeywins and the write never reaches the service.
Whether that override is intended is an open design question rather than a settled hole: the query-side escape hatch was deliberate, and the mutation side mirrors it. Either way it is not closed by shadowing instance methods, so it needs its own decision and its own guard.
Solution
Mirror the existing invalidateQueries shadow. 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. Note there are now two shadows on the returned client, invalidateQueries and defaultMutationOptions, so the guards compose with them rather than replacing them.
Methods to guard:
setQueryDefaults— per-key cache-policy override; ADR 0020 moves cache policy to the service layersetMutationDefaults— data-service mutations exist as of #9324 (mutations in BaseDataService), so this is now live rather than preemptivesetDefaultOptions— block only whenoptions.queries.queryFnoroptions.mutations.mutationFnis setprefetchQuery/prefetchInfiniteQuery— pending policy decision on whether UI-side prefetch is in scope; block until decidedfetchQuery/fetchInfiniteQuery— samesetQueryData/setQueriesData— block; replacement implementation tracked separately (see Dependencies)ensureQueryData/ensureInfiniteQueryData— block; replacement implementation tracked separately (see Dependencies)getMutationCache/resumePausedMutations/isMutating— mutation-side twins, needed since #9324 (mutations in BaseDataService)
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
- A caller-supplied
queryFnormutationFnon a data-service key is decided one way or the other, and whichever way it goes is enforced at runtime rather than only in the wrapper's types -
setDefaultOptionsonly throws whenoptions.queries.queryFnoroptions.mutations.mutationFnis set; other client-wide tuning unaffected - Non-data-service keys pass through for all methods (Option C hooks unaffected)
-
invalidateQueriesanddefaultMutationOptionsshadows, wrapper hooks, andhydrate-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 (Expose replacement implementations of QueryClient APIs in UI)
Widened by: #9324 (Update BaseDataService to accommodate mutations) — adds the mutation proxy and the mutation-side instance methods
- 主要语言
- TypeScript
- 星标
- 422
- 派生
- 313
- 平均合并
- 1 天 8 小时
- 30 天内合并 PR
- 414
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
MetaMask/core 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
CI: "Validate changelog diffs" job fails on every fork-sourced pull request可能已有人在做 @Roxen-AS 于 20 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
platform-api-docs: `scan` strategy misses ESM-only packages, which ship `.d.ts` rather than `.d.cts`可能已有人在做 @gaohan1994 于 21 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
[utils] Replace the `uuid` dependency with `crypto.randomUUID()`可能已有人在做 @avantikonde 于 34 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
MetaMask/core#10210 · 1 个 reaction ·
维护者通常 1 天内回复
-
[utils] `toWei` accepts fractional wei and returns wrong values可能已有人在做 @Roxen-AS 于 20 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
相似的 Issue
-
enhancement module: library-ui
难度 2/5 1-3 小时 新手友好度 65/100
chthollyphile/folia-major#1206 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
typescript-eslint/typescript-eslint#13189 ·
维护者通常 2 天内回复
-
severity:medium triage:confirmed triage:in-progress triage:reproduced
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
wrong type
难度 2/5 1-3 小时 新手友好度 70/100
elastic/elasticsearch-specification#6919 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复