Evaluate signed-zero equality for QueryObserver snapshots

未关闭
#12,567 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript
领域
frontend, testing

调研方向

Start with the signed-zero regression case in packages/query-core/src/__tests__/queryObserver.test.tsx, then read the result comparison in packages/query-core/src/queryObserver.ts and shallowEqualObjects in packages/query-core/src/utils.ts. This issue asks maintainers to decide the intended equality semantics, including effects on notifications, NaN, and snapshot caching; it is design work rather than a scoped first contribution. Done means the behavior is documented and, if changed, regression tests cover the optimistic result, current snapshot, and affected equality and notification behavior.

由索引模型根据 Issue 内容生成。

描述

Summary

Evaluate whether QueryObserver snapshots should distinguish -0 from 0 when selected placeholder data changes. This is a follow-up for maintainers to decide the desired equality semantics; it does not assume that a global equality change is required.

Reproduction and current behavior

In the signed-zero regression case in packages/query-core/src/__tests__/queryObserver.test.tsx, create an observer with enabled: false, placeholderData: 1, structuralSharing: false, and a selector returning -0. Update the options to use a selector returning 0, then call getOptimisticResult with the updated options.

The PR author verified that the optimistic result contains 0, while getCurrentResult().data still contains -0. The shallow comparison treats these values as equal and preserves the current snapshot. The useQuery render in this case uses the optimistic result.

Decision and affected areas

Review the observer result comparison and update behavior in packages/query-core/src/queryObserver.ts and shallowEqualObjects in packages/query-core/src/utils.ts. Consider whether signed zeros should count as different, and whether any change should be local to observer results or use Object.is semantics more broadly. Assess effects on notifications, render optimizations, other equality cases such as NaN, and the useSyncExternalStore snapshot caching contract.

Acceptance criteria

  • Maintainers decide and document the intended signed-zero behavior for observer snapshots.
  • If a change is warranted, implement the chosen behavior without breaking snapshot stability or notification semantics.
  • If a change is made, add regression coverage for the chosen behavior, including the optimistic result and current snapshot, and cover any affected equality and notification behavior.

Context

主要语言
TypeScript
星标
50.6k
派生
4.2k
平均合并
8 小时 37 分钟
30 天内合并 PR
450

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/query 的其他 Issue

查看 TanStack/query 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。