A context reader inside a suspended boundary keeps the old value after its provider commits (regression from #133)
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- react, typescript
- 領域
- frontend
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- TypeScript
- 星號
- 640
- 分支
- 32
- 平均合併
- 1 小時 15 分鐘
- 30 天內合併 PR
- 7
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/redact 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 70/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
相似的 Issue
-
bug data-types
難度 2/5 1-3 小時 新手友好度 88/100
ClickHouse/clickhouse-js#1293 ·
維護者通常 1 天內回覆
-
area: middleware enhancement good first issue
難度 2/5 1-3 小時 新手友好度 68/100
-
agent/quality testing
難度 1/5 1 小時以內 新手友好度 95/100
維護者通常 1 天內回覆
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 92/100
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
juspay/agent-distro#203 ·
維護者通常 1 天內回覆