`lazy(memo(Component))` doesn't re-render on store update when an ancestor reads the same store
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 停滞
- 技術スタック
- react, typescript
- 領域
- frontend
調査の方向性
The issue names renderNode, renderMemo, and the regression test tests/lazy-memo-store-update.test.tsx. Read the linked fix commit and that test first to understand the change already made. The reported behavior is reproduced when the ancestor and lazy memo component subscribe to the same store; the issue is already addressed by the linked commit.
索引モデルが issue の本文から書いたものです。
説明
In our dashboard, a navbar drawer is loaded with lazy(() => import(...)) and wrapped in memo. It reads a value from an external store with useSyncExternalStore. The layout route reads the same store to show the panel title.
When the panel opened, the layout updated (the title switched), but the drawer never re-rendered when redact is enabled. It kept isOpen === false, so the panel stayed empty. No error, nothing in the console. It works with React, and it works as soon as you drop either lazy or memo.
Repro
const store = createStore(false) // minimal subscribe/getSnapshot store
const Panel = lazy(async () => ({
default: memo(() => {
const isOpen = useSyncExternalStore(store.subscribe, store.get)
return <span id="child">{String(isOpen)}</span>
}),
}))
const App = () => {
const isOpen = useSyncExternalStore(store.subscribe, store.get)
return (
<div title={String(isOpen)}>
<Suspense fallback="Loading"><Panel /></Suspense>
</div>
)
}
// after mount:
store.set(true)
// parent title -> "true"
// #child -> still "false"
Cause
renderNodeclearsfiber.gfor every tag exceptMemo, so memo can still see a pending update. A lazy fiber delegates to its resolved memo on the same fiber, but Lazy wasn't exempt. By the timerenderMemoruns the flag is gone, so it bails on equal props. Then the component's own queued update gets skipped because g is already false. That only happens when the ancestor renders first in the same pass, which is why both subscribing to the same store matters.
Fix
Keep the flag on lazy fibers like Memo does, and clear it when the lazy suspends. Regression test included: tests/lazy-memo-store-update.test.tsx.
Fix: https://github.com/aymericzip/redact/commit/0b0e5f6e4428b5d79956cf84be1e8c99f8139ea1
- 主要言語
- TypeScript
- スター
- 581
- フォーク
- 28
- 平均マージ
- 13時間 48分
- マージ済み PR(30日)
- 45
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TanStack/redact のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
TanStack/redact#142 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
TanStack/redact#166 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
TanStack/redact の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
ilan-pinto/roaring-lions#1552 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug: [React Native/Android] KeepAliveService never starts when CAMERA is not granted (Android 14+)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cloudflare/realtimekit-ui#208 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
usebruno/bruno-vscode#235 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信