Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode

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

@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

环境准备

从这里开始

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

testing-library/react-testing-library 的其他 Issue

查看 testing-library/react-testing-library 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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