useSyncExternalStore does not bail out when the snapshot returns to the committed value: inline ref writing to a store loops forever (0.2.6)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 55/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- react, typescript, vite
- 領域
- frontend
調査の方向性
Start with the reproduction in app.jsx and build it with and without the Redact plugin using vite build. Trace how Redact handles useSyncExternalStore when a render returns to the committed snapshot; done means the inline ref no longer causes repeated commits and the render bails out when the snapshot is unchanged.
索引モデルが issue の本文から書いたものです。
説明
What happens
A component that reads a value with useSyncExternalStore and passes an inline ref callback that writes its node into the same store never settles under Redact. On every commit the old ref is called with null and the new ref with the node, so the store goes node → null → node and ends where it started. React re-renders, sees the snapshot equals the committed value, bails out (the new output and its new inline ref are discarded) and stops. Redact re-renders, commits the new inline ref, and the cycle repeats.
- React 19: 3 renders, input mounted, no errors.
- Redact 0.2.6, production build, Chromium 151 (Playwright, bundled headless): the main thread never yields;
page.gototimes out after 30 s. - Redact 0.2.6 in Vitest/jsdom (dev build):
flushPending exceeded 50 iterations — suspected infinite update loop.
Inline ref callbacks are allowed in React, and this store-plus-ref shape is common in component libraries. We first hit it through Base UI's Combobox input (its setInputElement writes the input into the component store), where a parent passed an inline ref.
Reproduction
index.html
<!doctype html><html><body><div id="root"></div><script type="module" src="./app.jsx"></script></body></html>
app.jsx
import { useSyncExternalStore } from 'react';
import { createRoot } from 'react-dom/client';
let value = null;
const listeners = new Set();
window.renders = 0;
const store = {
get: () => value,
set(next) { if (next !== value) { value = next; listeners.forEach((l) => l()); } },
subscribe(l) { listeners.add(l); return () => listeners.delete(l); },
};
function Field() {
window.renders++;
const el = useSyncExternalStore(store.subscribe, store.get);
return <input data-has-el={String(el != null)} ref={(node) => store.set(node)} />;
}
createRoot(document.getElementById('root')).render(<Field />);
Build with vite build with and without the redact() plugin (plus @vitejs/plugin-react) and open the result.
Expected
Like React: when a useSyncExternalStore re-render produces a snapshot equal to the one already committed (Object.is) and nothing else changed, bail out of that render instead of committing it.
Workaround on our side: give the input a stable useCallback ref.
- 主要言語
- TypeScript
- スター
- 537
- フォーク
- 22
- 平均マージ
- 11時間 28分
- マージ済み PR(30日)
- 34
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/redact のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TanStack/redact#142 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
TanStack/redact#141 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
TanStack/redact#139 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
TanStack/redact の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
bug needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
DSpace/dspace-angular#6511 ·
メンテナーはふだん 1 日以内に返信
-
area: frontend area:byok bug severity:low
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Phone app shows Unknown for a remote machine whose key changed対応中かも @janicduplessis が今日担当しました。 オープンarea: mobile priority: P3 type: bug
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
appandflow/stim#5006 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Area - Local to Cloud Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
microsoft/vscode-mssql#23209 ·
メンテナーはふだん 1 日以内に返信