-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
revalidateOnMount not working on react-native #471
Comments
revalidateOnMount
not working on react-native
Okay so I was logging a bit more, and I think I know what's happening. RN uses a polyfill for the window object (https://github.com/facebook/react-native/blob/master/Libraries/Core/setUpGlobals.js), and I see that there's a check like this in // trigger a revalidation
if (config.revalidateOnMount ||
(!config.initialData && config.revalidateOnMount === undefined)) {
if (typeof latestKeyedData !== 'undefined' &&
!IS_SERVER &&
window['requestIdleCallback']) {
// delay revalidate if there's cache
// to not block the rendering
window['requestIdleCallback'](softRevalidate);
}
else {
softRevalidate();
}
} So problem is is that EDIT: |
hey @svenlombaert thanks for reporting this! |
Well actually RN polyfills it, it's just not getting executed on their side since v0.62.2 (facebook/react-native#28602). So not sure if anything needs to change to be honest? You can see So since window. requestIdleCallback does exist in RN, that PR won't fix much, I think? |
sounds more like a bug on RN side? window.requestIdleCallback = (fn) => setTimeout(fn, 1) |
@svenlombaert I just tried your demo, config useSWR with the following options which are borrowed from #450 revalidateOnMount: true,
revalidateOnFocus: false,
revalidateOnReconnect: false,
refreshWhenOffline: false,
refreshWhenHidden: false,
refreshInterval: 0 and test it with an iphone device, it works for me (each toggle on will revalidate the user). but I saw the version of swr is 0.2.0, could you confirm is it still reproducible with the latest version of swr? since |
I upgraded to the latest version of |
Just to cross post this here, I have found the issue that's causing this and submitted a PR to fix it. It's easy to fix this yourself using patch-package. |
Hi, is there any update on this? I can see the PR is still open in ReactNative |
Close this as it's more like a react native runtime issue |
Bug report
Description / Observed Behavior
I added
revalidateOnMount
option to useSWR, but it doesn't seem to revalidate, no requests get fired after I open a screen for the second time.Expected Behavior
It should revalidate all requests when re-opening screen
Repro Steps / Code Example
I tried to prove the bug, but here I have the complete opposite behaviour. Can't turn the revalidation off 😕
https://snack.expo.io/@svrnlombaert/thoughtful-apple
The text was updated successfully, but these errors were encountered: