`lazy(memo(Component))` doesn't re-render on store update when an ancestor reads the same store
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- react, typescript
- Área
- frontend
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 581
- Forks
- 28
- Merge medio
- 13 h 48 min
- PR fusionados (30 d)
- 45
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/redact
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
TanStack/redact#142 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
TanStack/redact#166 · 1 reacción ·
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/redact
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
ilan-pinto/roaring-lions#1552 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug: [React Native/Android] KeepAliveService never starts when CAMERA is not granted (Android 14+)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
cloudflare/realtimekit-ui#208 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
usebruno/bruno-vscode#235 ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día