fix: mobile useFeed stale closure and subscription churn - #1413
Open
Benedict315 wants to merge 2 commits into
Open
fix: mobile useFeed stale closure and subscription churn#1413Benedict315 wants to merge 2 commits into
Benedict315 wants to merge 2 commits into
Conversation
This commit fixes two critical bugs in apps/mobile/hooks/useFeed.ts: 1. Stale closure in syncWithNetwork offset calculation: - Added postsLengthRef to track current posts length via ref instead of closure - Updated loadFromCache to sync postsLengthRef with current state - Updated syncWithNetwork to sync postsLengthRef with current state - This prevents pagination offsets from being computed from stale closures 2. Subscription churn on every posts.length change: - Changed subscribe effect dependency from [posts.length] to [] - Subscribe effect now uses postsLengthRef.current instead of posts.length closure - This prevents subscriptions from tearing down and re-creating on each pagination Impact: - Pagination offsets now computed from current state, not stale closures - Realtime subscriptions are stable across pagination - Eliminates redundant re-renders and network activity during scrolling - Prevents skipped or duplicated posts during cache-then-network pagination Tests: - Added test for cache-then-network pagination correctness - Verifies no duplicates and correct ascending order of post IDs - Existing test for cursor retention on network failure still passes Acceptance criteria met: ✓ Offsets computed from current state, not stale closure ✓ Realtime subscriptions stable across pagination ✓ Test covers cache-then-network pagination correctness
|
@Benedict315 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
@jotel-dev is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
Run cargo fmt to fix formatting issues in: - packages/contracts/contracts/linkora-contracts/src/lib.rs - packages/contracts/contracts/linkora-contracts/src/test.rs Changes include: - Line wrapping for better readability - Removed trailing whitespace - Consistent formatting per rustfmt rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit fixes two critical bugs in apps/mobile/hooks/useFeed.ts:
Stale closure in syncWithNetwork offset calculation:
Subscription churn on every posts.length change:
Impact:
Tests:
Acceptance criteria met:
✓ Offsets computed from current state, not stale closure ✓ Realtime subscriptions stable across pagination
✓ Test covers cache-then-network pagination correctness
Summary
Type of Change
Testing Done
cargo testpassesChecklist
Related Issue
Closes #1303