Skip to content

Share tab loses state on tab switch (slow workaround in place) #4

@darthnithin

Description

@darthnithin

Problem

When switching from Request tab back to Share tab, the component loses all state:

  • GET link status shows as unlinked
  • Donation status (isActive) resets to false
  • Shows 'Start Sharing' card instead of Impact card
  • Account balances disappear

Root Cause

The Share tab component appears to be remounting when switching tabs, despite using NativeTabs which should keep components mounted. This may be a bug in:

  • NativeTabs implementation in SDK 54
  • Nested route groups (share) and (request)
  • Expo Router tab handling

Current Workaround

Added useFocusEffect hook that reloads all data when tab comes into focus:

  • GET link status (getGetLinkStatus)
  • GET account balances (getGetAccounts)
  • Donation impact data (getDonorImpact)

File: apps/mobile/app/(tabs)/(share)/index.tsx

Why It's Slow

Makes 3 API calls every time you switch tabs:

  1. getGetLinkStatus(userId)
  2. getGetAccounts(userId)
  3. getDonorImpact(userId)

This is noticeable lag when switching tabs.

Ideal Solutions

Option 1: Fix Root Cause

Investigate why component is remounting and prevent it:

  • Check NativeTabs behavior in SDK 54
  • Test if upgrading to SDK 55 stable (when released) fixes it
  • Try different tab layout configurations

Option 2: Cache State in Context

Move GET/donation state to a context provider (similar to TabCacheProvider) so it persists across remounts:

  • Create DonorStateProvider
  • Store isGetLinked, isActive, monthlyAmount, etc.
  • Only make API calls on initial load and explicit refresh

Option 3: Throttle Refresh

Only refresh data if >30 seconds since last refresh, not on every tab switch.

Acceptance Criteria

  • Tab switching is instant (no API calls or <100ms)
  • State persists correctly across tab switches
  • Fresh data still loads on initial mount and pull-to-refresh

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions