Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using useDeferredValue and Suspense unexpectedly shows fallback in ios/android but correctly shows stale state in web #50078

Open
andrew-wang-polar opened this issue Mar 17, 2025 · 2 comments
Labels
Needs: Attention Issues where the author has responded to feedback.

Comments

@andrew-wang-polar
Copy link

andrew-wang-polar commented Mar 17, 2025

Description

I'm following the examples from React on using useDeferredValue and Suspense to show a stale state. The correct behavior should be to show the fallback only on the first load, and then on subsequent queries (e.g. when typing in the search box or incrementing counter in the examples) show a stale state until new data is loaded (which then should replace the stale state). I've included an expo snack.

The correct behavior is observed in React Native web. However for android/ios the fallback always shows. For the snack I'm using React Native 0.76.7, which is the default version that a new expo project installs. I've also tested on 0.77.1 but get the same behavior.

In my actual project where I have ios/android folders I've tried explicitly setting newArchEnabled/isConcurrentRootEnabled like some of these older articles suggest, see here. However, the same behavior is observed with that as well.

Steps to reproduce

  1. Go to the expo snack https://snack.expo.dev/@polarwang/reactnative-suspense-usedeferredvalue-bug

React Native Version

0.76.7

Affected Platforms

Other (please specify)

Output of npx @react-native-community/cli info

info Fetching system and libraries information...
System:
  OS: macOS 15.2
  CPU: (16) arm64 Apple M3 Max
  Memory: 3.03 GB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.9.0
    path: ~/.nvm/versions/node/v20.9.0/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v20.9.0/bin/yarn
  npm:
    version: 10.1.0
    path: ~/.nvm/versions/node/v20.9.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12700392
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: javac 22
    path: /Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: latest
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.7
    wanted: 0.76.7
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

info React Native v0.78.0 is now available (your project is running on v0.76.7).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.78.0
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.76.7&to=0.78.0
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

There is no stacktrace but the behavior is illustrated in the snack

Reproducer

https://snack.expo.dev/@polarwang/reactnative-suspense-usedeferredvalue-bug

Screenshots and Videos

No response

@shubhamguptadream11
Copy link
Collaborator

@andrew-wang-polar This seems to be working with code you provided. I checked this on 0.77.0 react native version.

Simulator.Screen.Recording.-.iPhone.15.Plus.-.2025-03-18.at.16.11.51.mp4

@andrew-wang-polar
Copy link
Author

@shubhamguptadream11 thanks for looking. In the screen recording you showed, the fallback (the loading spinner) is showing. However, the behavior I expect (and that is showing on web) is that the border color from the isQueryStale check should show. The relevant section is here:

<Suspense fallback={
  <View style={styles.loading}>
    <ActivityIndicator size="large" color="green" />
    <Text style={styles.loadingText}>Loading...</Text>
  </View>
}>
  <View style={[styles.results, { borderColor: isQueryStale ? 'red' : 'black' }]}>
    <SearchResults query={deferredQuery} />
  </View>
</Suspense>

See the attached screen recording with the expected behavior.

Screen.Recording.2025-03-18.at.8.18.33.AM.mov

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Attention Issues where the author has responded to feedback.
Projects
None yet
Development

No branches or pull requests

3 participants