`lazy(memo(Component))` doesn't re-render on store update when an ancestor reads the same store
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- react, typescript
- Ambito
- frontend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- TypeScript
- Stelle
- 581
- Fork
- 28
- Merge medio
- 13h 48m
- PR unite (30g)
- 45
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/redact
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TanStack/redact#142 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
TanStack/redact#166 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/redact
Issue simili
-
Type/Improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
OpenNSW/nsw-srilanka#1259 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
oxc-project/tsrs#1010 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Fission-AI/OpenSpec#2260 ·
I maintainer di solito rispondono entro 1 giorno
-
Add: ESP 1 UKApertacheck:passed streams:add
Difficoltà 1/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
area:infra area:storage bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
THU-MAIC/OpenMAIC#2311 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno