Skip to content

Make suspense use branches explicit - #4281

Draft
devjiwonchoi wants to merge 1 commit into
mainfrom
jiwon/swr-suspense-use-branches
Draft

Make suspense use branches explicit#4281
devjiwonchoi wants to merge 1 commit into
mainfrom
jiwon/swr-suspense-use-branches

Conversation

@devjiwonchoi

@devjiwonchoi devjiwonchoi commented Jun 23, 2026

Copy link
Copy Markdown
Member

Why?

Make the Suspense use(...) paths easier to debug by replacing ternary-selected promises with explicit branches. This lets a debugger land directly on the preload mutation path, revalidation path, or resolved no-op path.

@devjiwonchoi devjiwonchoi changed the title [codex] Make suspense use branches explicit Make suspense use branches explicit Jun 23, 2026
@saintparish4

Copy link
Copy Markdown

While making the suspense use() branches explicit, the if (suspense) guard in shouldStartRequest (use-swr.ts:228) is worth folding into the same cleanup: both arms return the identical isUndefined(data) || revalidateIfStale, so the guard is dead. It also reads inconsistently against the sibling shouldDoInitialRevalidation block (use-swr.ts:379), which uses isUndefined(data) ? false : revalidateIfStale. I added a characterization test over the suspense initial-revalidation matrix (no- data -> suspends; cached + revalidateIfStale:false -> no fetch; cached + revalidateIfStale:true -> revalidates once); the whole suspense suite stays greeen under both expressions, so they only differ in the suspense+no-data case, which suspends before the snapshot surfaces -- the two are behavior-equivalent and line 228 can be simplified (or aligned with 379) safely. Happy to PR the cleanup + test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants