useThrottle stops updating after React 18 StrictMode effect replay
まだ誰も着手していません。
評価
- 難易度
- 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 はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
streamich/react-use のほかの issue
-
Add Generic Fn for useDebounce対応中かも @itsmejay80 が 189 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
useVideo.story.tsx - sampleVideo can not be loaded再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
-
useSlider: event callbacks are not updated対応中かも @erykpiast が 1836 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
streamich/react-use の issue をすべて見る
似ている issue
-
area:security documentation effort:S priority:P2
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
app:web meta:ops
難易度 2/5 半日 初心者へのやさしさ 78/100
osu-tournament-rating/otr#1113 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
typegoose/mongodb-memory-server#1040 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100