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

useThrottle stops updating after React 18 StrictMode effect replay

Abierto Apto para principiantes
#2,718 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
react, typescript
Área
frontend

Línea de trabajo

Comienza con el hook useThrottle y su limpieza useUnmount; después, reproduce el problema con el ejemplo de React 18 StrictMode del informe. Añade una prueba de regresión de StrictMode que cubra el timeout cancelado y el valor pendiente, y verifica que throttledValue se actualice dentro del intervalo configurado después de la corrección.

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

Descripción

Description

useThrottle stops publishing new values when used inside React 18 StrictMode.

During the StrictMode effect replay, the useUnmount cleanup clears the pending timeout but leaves timeout.current set to the ID of the cancelled timeout.

When the effects are mounted again, useThrottle assumes that a timeout is still active. Subsequent values are only written to nextValue.current, but the cancelled callback can no longer publish them or reset timeout.current.

As a result, the throttled value stops updating indefinitely.

Environment
  • react-use: 17.6.1 (also reproducible with 17.6.0)
  • react: 18.3.1
  • react-dom: 18.3.1
Reproduction
import React, { StrictMode, useState } from 'react';
import { createRoot } from 'react-dom/client';
import { useThrottle } from 'react-use';

const App = () => {
  const [value, setValue] = useState(0);
  const throttledValue = useThrottle(value, 100);

  return (
    <>
      <button onClick={() => setValue((current) => current + 1)}>
        Increment
      </button>
      <div>Value: {value}</div>
      <div>Throttled value: {throttledValue}</div>
    </>
  );
};

createRoot(document.getElementById('root')).render(
  <StrictMode>
    <App />
  </StrictMode>
);

Click Increment after the initial StrictMode effect replay.

Expected behavior

throttledValue is updated within the configured throttle interval.

Actual behavior

value changes, but throttledValue remains unchanged indefinitely.

Suggested fix

Reset the timeout ref and pending-value flag during cleanup:

useUnmount(() => {
  if (timeout.current) {
    clearTimeout(timeout.current);
  }

  timeout.current = undefined;
  hasNextValue.current = false;
});

This allows the remounted effect to create a new timeout instead of treating the cancelled timeout as active.

I can submit a pull request with the fix and a StrictMode regression test if this approach is acceptable.

Lenguaje dominante
TypeScript
Estrellas
44k
Forks
3.3k
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 streamich/react-use

Todos los issues de streamich/react-use

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.