bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode
@suhailopensource 已经在做这个了。
开始于 2026年7月29日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- javascript
- 领域
- testing
调研方向
从 src/config.js 中的 configure() 开始,然后检查 getConfig() 如何公开已保存的 reactStrictMode 值。当后续调用 configure() 时省略 reactStrictMode 仍能保留之前的设置(包括复现步骤中描述的普通对象情况)后,修复就完成了。
由索引模型根据 Issue 内容生成。
描述
Bug
Calling configure() with any config object that omits reactStrictMode silently resets the previously-configured strict mode flag to undefined.
Root cause
In src/config.js:
function configure(newConfig) {
if (typeof newConfig === 'function') {
newConfig = newConfig(getConfig())
}
const {reactStrictMode, ...configForDTL} = newConfig
configureDTL(configForDTL)
configForRTL = {
...configForRTL,
reactStrictMode, // <-- always overwrites, even when undefined
}
}
When newConfig does not include a reactStrictMode key, destructuring yields reactStrictMode = undefined. The spread ...configForRTL correctly carries the previously saved value, but the explicit reactStrictMode property after it overwrites it with undefined.
Reproduction
import { configure, getConfig } from '@testing-library/react'
// Enable strict mode
configure({ reactStrictMode: true })
console.log(getConfig().reactStrictMode) // true ✓
// Later, an unrelated configure() call — e.g. from a setup file
configure({ asyncUtilTimeout: 2000 })
console.log(getConfig().reactStrictMode) // undefined ✗ (expected: true)
The second configure() call erases the strict-mode setting. The function-form callback is affected identically:
configure(prev => ({ ...prev, asyncUtilTimeout: 2000 }))
// Works because prev spreads reactStrictMode — but only if callers remember to spread prev.
// The plain-object form has no such safety net.
Impact
Tests that rely on global strict-mode configuration (e.g. set in a setupFilesAfterFramework) silently lose that configuration if any later configure() call omits reactStrictMode. This is particularly easy to hit when test utilities or libraries call configure() with their own options.
Fix
Only write reactStrictMode into configForRTL when it is explicitly present in newConfig:
configForRTL = {
...configForRTL,
...(reactStrictMode !== undefined && {reactStrictMode}),
}
PR #1461 implements exactly this fix.
- 主要语言
- JavaScript
- 星标
- 19.7k
- 派生
- 1.2k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
testing-library/react-testing-library 的其他 Issue
-
fireEvent.select does not wrap its automatic native focus in act可能已有人在做 @sergioperezcheco 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 4/5 3-5 天 新手友好度 30/100
testing-library/react-testing-library#1459 · 2 条评论 ·
-
perf: optimize container lookup with early exit可能重新可做 @Ch-Abhinav-Chowdary 于 298 天前认领,目前没有进行中的 PR。 未关闭
难度 1/5 1 小时以内 新手友好度 35/100
testing-library/react-testing-library#1430 · 1 条评论 ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)可能已有人在做 @swarnim02 于 315 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 42/100
testing-library/react-testing-library#1421 · 1 条评论 ·
查看 testing-library/react-testing-library 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
NaturalIntelligence/fast-xml-parser#888 · 1 条评论 ·
维护者通常 2 天内回复
-
bug callouts regression revealjs
难度 2/5 1-3 小时 新手友好度 72/100
quarto-dev/quarto-cli#15014 ·
维护者通常 1 天内回复
-
check:passed feeds:remove
难度 1/5 1 小时以内 新手友好度 65/100
iptv-org/database#37176 · 1 条评论 · 1 个 reaction ·
维护者通常 9 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
hawk-digital-environments/HAWKI#443 ·
维护者通常 1 天内回复
-
documentation v2
难度 2/5 1-3 小时 新手友好度 82/100
modelcontextprotocol/python-sdk#3662 ·
维护者通常 1 天内回复