[GH-ISSUE #6879] useSession().isPending flickers on app focus (React Native) #27985

Closed
opened 2026-04-17 19:18:21 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @marcospgp on GitHub (Dec 19, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6879

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

useSession().isPending flickers on app focus (React Native)

When using useSession() in React Native, isPending briefly becomes true when the app regains focus (e.g., switching apps, returning from Apple Sign In modal). This causes UI flicker if you conditionally render based on isPending.

Reproduction

  1. Authenticate user
  2. Switch to another app
  3. Switch back
  4. isPending flashes true → loading UI flickers

Expected

isPending should only be true during initial session fetch, not on refocus/refetch when data already exists.

Workaround

Use data !== undefined instead of !isPending for initial load checks.

// ❌ Flickers on app focus                                                                                                                                                                                       
if (isPending) return <Loading />                                                                                                                                                                                 
                                                                                                                                                                                                                  
// ✅ Works                                                                                                                                                                                                       
if (data === undefined) return <Loading />                                                                                                                                                                        

Environment

  • Platform: React Native (Expo)
  • better-auth: 1.4.6
  • @better-auth/expo: 1.4.6

Current vs. Expected behavior

see above

What version of Better Auth are you using?

see above

System info

see above

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)


Additional context

No response

Originally created by @marcospgp on GitHub (Dec 19, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6879 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ## `useSession().isPending` flickers on app focus (React Native) When using `useSession()` in React Native, `isPending` briefly becomes `true` when the app regains focus (e.g., switching apps, returning from Apple Sign In modal). This causes UI flicker if you conditionally render based on `isPending`. ### Reproduction 1. Authenticate user 2. Switch to another app 3. Switch back 4. `isPending` flashes `true` → loading UI flickers ### Expected `isPending` should only be `true` during initial session fetch, not on refocus/refetch when data already exists. ### Workaround Use `data !== undefined` instead of `!isPending` for initial load checks. ```tsx // ❌ Flickers on app focus if (isPending) return <Loading /> // ✅ Works if (data === undefined) return <Loading /> ``` ### Environment - Platform: React Native (Expo) - `better-auth`: 1.4.6 - `@better-auth/expo`: 1.4.6 ### Current vs. Expected behavior see above ### What version of Better Auth are you using? see above ### System info ```bash see above ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-17 19:18:21 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 19, 2025):

The flickering issue with useSession().isPending in React Native when the app regains focus has been noted. When switching apps or returning from modals, isPending briefly becomes true, causing UI flicker. The expected behavior is for isPending to reflect only the initial session fetch status, not on focus changes.

A recommended workaround is to check for the session data directly, rather than relying on isPending. For example, use if (data === undefined) return <Loading /> instead of checking for isPending which can lead to flickering due to the transient state change when regaining app focus [1].

Are you considering implementing this workaround, or do you need assistance with any other part of your setup?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3675230012 --> @better-auth-agent[bot] commented on GitHub (Dec 19, 2025): The flickering issue with `useSession().isPending` in React Native when the app regains focus has been noted. When switching apps or returning from modals, `isPending` briefly becomes `true`, causing UI flicker. The expected behavior is for `isPending` to reflect only the initial session fetch status, not on focus changes. A recommended workaround is to check for the session data directly, rather than relying on `isPending`. For example, use `if (data === undefined) return <Loading />` instead of checking for `isPending` which can lead to flickering due to the transient state change when regaining app focus [[1]](https://github.com/better-auth/better-auth/issues/4609). Are you considering implementing this workaround, or do you need assistance with any other part of your setup? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@marcospgp commented on GitHub (Dec 19, 2025):

this issue https://github.com/better-auth/better-auth/issues/4609 is unrelated

<!-- gh-comment-id:3675254844 --> @marcospgp commented on GitHub (Dec 19, 2025): this issue https://github.com/better-auth/better-auth/issues/4609 is unrelated
Author
Owner

@Glovvie commented on GitHub (Dec 29, 2025):

Hi! I am also rendering conditionally based on useSession isPending within nextjs app and I, too, would expect isPending be true only during initial session fetch, not on refocus/refetch when data already exists

Unless I am doing something wrong, it doesn't seem to be the case in v1.5.0-beta.1 and 1.4.9

<!-- gh-comment-id:3695276210 --> @Glovvie commented on GitHub (Dec 29, 2025): Hi! I am also rendering conditionally based on useSession isPending within nextjs app and I, too, would expect isPending be true only during initial session fetch, not on refocus/refetch when data already exists Unless I am doing something wrong, it doesn't seem to be the case in v1.5.0-beta.1 and 1.4.9
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27985