Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

useThrottle stops updating after React 18 StrictMode effect replay

オープン 初心者向け
#2,718 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
react, typescript
領域
frontend

調査の方向性

useThrottle フックとその useUnmount クリーンアップから始め、次にレポートの React 18 StrictMode の例で問題を再現します。キャンセルされたタイムアウトと保留中の値を対象とする StrictMode のリグレッションテストを追加し、修正後に throttledValue が設定された間隔内で更新されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
44k
フォーク
3.3k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

streamich/react-use のほかの issue

streamich/react-use の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。