Skip to content

fix: resolve stale state in pull-to-refresh and tie spinner to actual data load (#1042)#1144

Open
vedant7007 wants to merge 1 commit into
SB2318:mainfrom
vedant7007:fix/pull-to-refresh-stale-state-1042
Open

fix: resolve stale state in pull-to-refresh and tie spinner to actual data load (#1042)#1144
vedant7007 wants to merge 1 commit into
SB2318:mainfrom
vedant7007:fix/pull-to-refresh-stale-state-1042

Conversation

@vedant7007
Copy link
Copy Markdown
Contributor

Closes #1042

pull-to-refresh was broken when the user scrolled past page 1. two bugs:

bug 1 — stale page closure: setPage(1) is async but page === 1 was read synchronously on the same tick. if user was on page 3, the condition failed and refetch() never ran.

bug 2 — premature spinner: setRefreshing(false) fired synchronously so the spinner disappeared instantly while data was still loading in the background.

what i fixed:

stale page (approach: remove guard, always refetch):

  • removed the if (page === 1) guard entirely — refetch() now always fires
  • when page is already 1, refetch re-fetches correctly. when page > 1, setPage(1) triggers a queryKey change that auto-fetches page 1
  • simpler than adding a flag + useEffect, works correctly in both cases

premature spinner (approach: useEffect on isFetching):

  • removed synchronous setRefreshing(false) from inside onRefresh
  • added useEffect watching [isFetching, refreshing] — spinner only dismisses when React Querys actual fetch completes
  • chose this over await refetch() because refetch() resolves for the current queryKey, not the page-1 auto-fetch after state change. isFetching correctly waits for ALL fetching to finish

bonus fixes:

  • allArticlesRef.current = [] on refresh — clears stale accumulated articles from pages 1-N
  • lastCategoryFilteredCountRef.current = -1 on refresh — resets sparse-category auto-pagination guard
  • removed unnecessary debug console.log in refresh handler

1 file changed. typecheck passes.

for labels i think gssoc:approved + level:intermediate + type:bug + quality:clean fits here. happy to make changes if needed!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Thank you @, for creating the PR and contributing to our UltimateHealth project 💗.
Our team will review the PR and will reach out to you soon! 😇
Make sure that you have marked all the tasks that you are done with ✅.
Thank you for your patience! 😀

@vedant7007
Copy link
Copy Markdown
Contributor Author

Hi maintainers,

Regarding the 3 failing checks — none are related to this PR's changes:

  1. Unit TestsGlossaryBottomSheet.test.tsx fails with No component given to styled() (Tamagui setup issue). All 77 actual tests pass. This is a recently added test that appears to be broken upstream.

  2. Knip Dead Code Check — The workflow references frontend/pnpm-lock.yaml for cache, but that file was removed in a recent commit. Fails before any analysis runs.

  3. PR Governance — Requires at least one label, which only maintainers can apply. Could you add bug when convenient?

PR #1122 has the same 3 failures for the same reasons. Typecheck, lint, and Expo Doctor all pass on this PR.

Happy to make any changes to the actual code if needed!

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.

[Bug] Pull-to-refresh reads stale React state — data refetch silently skips on non-first pages

1 participant