Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

fireEvent.select does not wrap its automatic native focus in act

Abierto Apto para principiantes
#1,471 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@sergioperezcheco ya está trabajando en esto.

Desde el 7/10/2026.

  • #1472 de @sergioperezcheco — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
88/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, react
Área
testing

Línea de trabajo

Empieza en src/fire-event.js en fireEvent.select, donde la llamada nativa node.focus() queda fuera del eventWrapper configurado que usan los dispatches de select/keyup circundantes. Lee cómo se configura eventWrapper (véase el envoltorio de act introducido en #685) y envuelve esa misma llamada nativa de focus, sin sintetizar eventos de focus ni reordenarlos. Listo significa que el repro del issue pasa — los atributos data-focused y data-blurred se vacían antes de que fireEvent.select devuelva y no hay advertencia de outside-act — con la suite src/__tests__ existente en verde; añade una test de regresión junto a los tests de select.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

This report was prepared with autonomous AI-agent assistance; it has not received human review.

On current main with React 18.3.1, fireEvent.select focuses an unfocused input or textarea, but React state updates in its onFocus and the previous element's onBlur are not flushed before the call returns. React also reports updates outside act.

import * as React from 'react'
import {render, screen, fireEvent} from '@testing-library/react'

function Example() {
  const [focused, setFocused] = React.useState(false)
  const [blurred, setBlurred] = React.useState(false)
  return <>
    <input aria-label="previous" onBlur={() => setBlurred(true)} />
    <input aria-label="selection" onFocus={() => setFocused(true)}
      data-focused={focused} data-blurred={blurred} />
  </>
}
render(<Example />)
screen.getByRole('textbox', {name: 'previous'}).focus()
const input = screen.getByRole('textbox', {name: 'selection'})
fireEvent.select(input)
expect(document.activeElement).toBe(input) // passes
expect(input.getAttribute('data-focused')).toBe('true') // receives false
expect(input.getAttribute('data-blurred')).toBe('true')

The existing native node.focus() call in src/fire-event.js is outside the configured eventWrapper, unlike the surrounding select and keyup dispatches. Wrapping that same native focus call fixes the focus/blur updates without synthesizing focus events or changing their order.

Verified against rebuilt original and fixed public dist/pure exports on macOS, Node 18.20.8/24.21.0, React 18.3.1 and jsdom 20.0.3. Formal regressions fail twice on original production with two passing controls. The existing worker_threads MessageChannel test shim keeps raw Jest alive after tests in this environment; an evidence-only native Node setImmediate bridge permits natural exit. No forced exit or repository configuration change is part of the fix.

Related: #685 established automatic act wrapping; #1214 proposes a broader asynchronous fireEvent API, and #1429 changes event argument forwarding. Neither wraps select's native focus call.

Lenguaje dominante
JavaScript
Estrellas
19.7k
Forks
1.2k
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de testing-library/react-testing-library

Todos los issues de testing-library/react-testing-library

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.