Conversation
communityMembershipProvider watched relaySessionProvider.notifier and was autoDispose, so every relay session rebuild (auth/config/age changes) and every consumer remount re-ran the HTTP /query round-trip. Read the notifier instead, keep the snapshot alive, and refresh only on explicit invalidation, community switch, or a completed (re)connect, matching channelMembersProvider. Fixes block#7734 Signed-off-by: UgaTheDev <kushzingade@honorsocietyofcinematicarts.org>
🔐 Codex Security Review
|
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.
Problem
communityMembershipProviderissues a freshPOST /queryfar more often than it needs to, showing up as/querybursts and aborted in-flight requests in the relay access log (#7734).Mechanism
mobile/lib/shared/community/community_membership_provider.dart:107-113. Two things compound:FutureProvider.autoDisposewith nokeepAlive(), so it is torn down whenever its last consumer (person_invite_section.dart,invite_create_provider.dart,currentCommunityRoleProvider) unmounts, and the next mount re-runs the body and re-queries. This is the half the regression test reproduces onmain.ref.watchesrelaySessionProvider.notifier, which makes it a dependent of the session notifier element, so anyRelaySessionNotifier.build()re-run (it watchesrelayConfigProvider,authProvider,ageSignalProvider) rebuilds this provider too. This half is by code reading: on Riverpod 3.1 a rawstate =emission does not propagate through.notifier, so the "session state changes" test in this PR passes onmainas well; the dependency bites onbuild()re-runs (auth / config / age-gate changes), which the test fake does not exercise.The sibling
channelMembersProvider(channel_management_provider.dart:512) already avoids both: itref.reads the notifier and usesref.listen(relaySessionProvider, ...)toinvalidateSelf()only on a transition intoconnected. This provider never got the same treatment.Fix
Mirror the sibling's session handling:
ref.readinstead ofref.watchon the notifier, and an explicitref.listenthat refetches only when the session transitions intoconnected. For the remount half,ref.keepAlive()rather than the sibling's snapshot cache — simpler, same effect for a single-instance provider. Community switches still invalidate via the existingref.watch(relayConfigProvider), and the explicitref.invalidate(communityMembershipProvider)retry paths (invite_create_page.dart,person_invite_section.dart) are unchanged.Membership is still enforced by the relay (VISION.md: "The relay enforces all access control"), so a snapshot that is stale until the next reconnect or explicit retry has the same staleness window channel members already accept.
Test
mobile/test/shared/community/community_membership_provider_test.dart— newcommunityMembershipProvider cachinggroup with a countingRelaySessionNotifierfake:reconnecting/disconnectedtransitions (passes onmaintoo, see above)main:Expected: <1> Actual: <2>main:Expected: <3> Actual: <2>(the reconnect refetch is new behavior, matching the sibling)Run locally with the Hermit-pinned Flutter:
flutter test6/6 on this branch;dart format --set-exit-if-changedclean;flutter analyzeclean.Duplicates
None found (
is:pr is:open 7734 in:body→ 0).Out of scope, same anti-pattern, worth a follow-up:
pulse_provider.dartandforum_provider.dartalsoref.watch(relaySessionProvider.notifier).Fixes #7734
🤖 Generated with Claude Code
https://claude.ai/code/session_01Qnxf2u2kSBxRM1AT7kD8BD