vercel / swr

React Hooks for Data Fetching
https://swr.vercel.app
MIT License
30.55k stars 1.22k forks source link

onSuccess not called after upgrading from Expo 51 to 52 #3040

Open ningacoding opened 1 day ago

ningacoding commented 1 day ago

Bug report

Description / Observed Behavior

onSuccess option is not called after upgrading from Expo 51 to 52

react: 18.3.1
expo: 52.0.4

Expected Behavior

onSuccess to be called after fetcher promise is resolved (WORKS on Web, the bug occurs on Android)

Repro Steps / Code Example

  import useSWRMutation from 'swr/mutation';

  const {
    data: pokemons,
    trigger: getPokemons,
    isMutating: isLoading
  } = useSWRMutation(url, {
    onSuccess: (result) => console.log(result), // not called // before upgrading this worked
  });

  useEffect(() => {
    getPokemons(); 
  }, []);

Additional Context

swr: 2.2.5

There is a chance this error is related to the new React Architecture since hooks also stop to propagate fetcher results.

in order to use the new React Architecture with Expo, create an Expo 52 project and add/update this line in app.json:

"newArchEnabled": true,

Under { "expo": { here } }

Re-launch app after clearing cache.

MasterSigmar commented 1 day ago

Getting something very similar here on our android dev build with new arch disabled :

"axios": "^1.7.7", <--- axios instance as fetcher
"expo": "^51.0.38",
"react": "18.2.0",
"react-native": "0.74.5",
"swr": "^2.2.5",
"typescript": "~5.3.3"

I even added resolutions to make sure peer deps use the same versions we have installed :

"resolutions": {
  "react": "18.2.0",
  "react-native": "0.74.5",
  "@types/react": "~18.2.45"
},
"packageManager": "yarn@4.2.2"

Adding a .then() to the fetcher seems like axios is correctly making the call and correctly returning the response to swr. Happens very intermittently, some calls work just fine and some don't. Seems pretty random, doesn't seem related to a certain endpoint. When that happens, onSuccess is indeed not called and the data returned by the swr hook is always undefined.

EDIT: lookin at the changelogs it seems that the last release for swr was in February and this issue has been a fairly recent(last couple of weeks) thing for us. Which makes me wonder if perhaps a peer deps or something that swr depends on might have introduced some kind of bug that makes this happen. 🤔

EDIT2: Could it be related to the latest android versions I wonder 🤔. Happens also on a tablet emulator on android 11.0 ("R") | x86 API 30 Phone/tablet, physical device/emulator doesn't seem to make a difference either.