A context reader inside a suspended boundary keeps the old value after its provider commits (regression from #133)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- 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
Start with tests/suspended-context-reader-retry.test.tsx, which exercises the locale transition and suspense-boundary retry described in the issue. Run that test, then inspect the context-propagation and suspense retry code affected by #133; the relevant implementation file is not identified in the issue. The work appears already implemented in commit 8a04ab7, so confirm that commit and run size:check on CI rather than starting a new patch.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
On our website, the locale switcher on documentation pages updates the locale in a transition (setLocale inside startTransition, read through context), then TanStack Router commits the new route through its stores. With 0.3.1 the page often kept the previous locale until a second click. That one is #130, fixed on main by #133 but not released yet.
To check the fix, I reproduced the same flow against main. The route's store update now goes through, but a component that reads the locale through context inside the page's <Suspense> keeps the old value once the boundary resolves, and nothing retries it. No error, nothing in the console. It works with React, and it works with 0.3.1.
Repro
const Locale = createContext('en')
let setLocale!: (locale: string) => void
function Provider({ children }: { children: ReactNode }) {
const [locale, set] = useState('en')
setLocale = set
return <Locale.Provider value={locale}>{children}</Locale.Provider>
}
// load(key) returns one pending promise per key (like an i18n cache)
function Body() {
const locale = useContext(Locale)
return <span>{locale === 'en' ? 'body-en' : use(load(`body-${locale}`))}</span>
}
function Page() {
const locale = useSyncExternalStore(route.subscribe, route.get) // the router's store
return <p>{locale === 'en' ? 'page-en' : use(load(`page-${locale}`))}</p>
}
const Outlet = memo(() => <Page />) // the router's Match / Outlet are memo
root.render(
<Provider>
<Suspense fallback={<i>loading</i>}>
<Body />
<Outlet />
</Suspense>
</Provider>
)
startTransition(() => setLocale('fr')) // held: Body suspends
route.set('fr') // Page suspends: the boundary shows its fallback
// then resolve both loads
// React 19.3.1 / redact 0.3.1: body-fr page-fr
// redact main: body-en page-fr
Cause
The route update suspends outside the transition, so the boundary shows its fallback. In the same flush the held transition renders again: the provider changes,
Bodyreadsfrand suspends, but the boundary already has a fallback, sorenderSuspenserewinds the attempt instead of throwing and the transition commits. The rewind givesBodyback its remembered context (en). When the boundary retries,Body's JSX is unchanged, so the stable-JSX bailout added in #133 skips it:ownContextChangedonly reports a change while a provider is rendering (changingProviders), and the provider has already committed. The boundary resolves withbody-enand nothing schedulesBodyagain. d9ac1c3, right before #133, rendersbody-fr.
Fix
After that rewind, flag the readers under the boundary whose remembered context differs from the changing provider as pending (fiber.g), so the retry renders them. React keeps the propagated context work on the fiber in the same situation. Regression test included: tests/suspended-context-reader-retry.test.tsx.
The fix costs about 30 B gzip; client total (default Vite) ends 5 B under budget. I measured with Node 22 because I don't have 24.22 locally, so size:check still needs a run on CI.
Fix: https://github.com/aymericzip/redact/commit/8a04ab7
Related issues: #130, #133
Since #133 also fixes #130, which we hit in production on 0.3.1, a patch release with both would help.
- Lingua principale
- TypeScript
- Stelle
- 640
- Fork
- 32
- Merge medio
- 1h 15m
- PR unite (30g)
- 7
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 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
TanStack/redact#195 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
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
Tutte le issue di TanStack/redact
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ClickHouse/clickhouse-js#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
agent/quality testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno