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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[馃悰] 馃敟 remote config method fetchAndActivate() inconsistent with method fetch() and then activate() on iOS only #7779

Open
2 of 10 tasks
JDMathew opened this issue May 5, 2024 · 3 comments
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report Platform: iOS Service: Remote Config Firebase Remote Config Workflow: Needs Review Pending feedback or review from a maintainer.

Comments

@JDMathew
Copy link
Contributor

JDMathew commented May 5, 2024

Issue

If you call await fetchAndActivate() remote config method on iOS it always returns a true value, even when new values were not fetched from the remote. This value contradicts the value returned by activate() when values were not fetched. A code snipped below can be used to test this:

 async function fetchAndActivateCompare() {
  const lastFetch = await remoteConfig().lastFetchStatus;
  console.log('Last fetch status: ', lastFetch);
  await remoteConfig().fetch();
  await remoteConfig()
    .activate()
    .then((didFetch) => {
      if (didFetch) {
        console.log('RemoteConfigs fetched from fetch and then activate.');
      } else {
        console.log('RemoteConfigs not fetched from fetch and then activate.');
      }
    });
    
  await new Promise((res) => setTimeout(res, 1000));

  const fetchedRemotely = await remoteConfig().fetchAndActivate()
  if (fetchedRemotely) {
    console.log('RemoteConfigs fetched from fetchAndActivate.');
  } else {
    console.log('RemoteConfigs not fetched from fetchAndActivate');
  }
}

// call init in useEffect somewhere in your app
const init = async () => {

  // set config
  await remoteConfig()
        .setConfigSettings({
          minimumFetchIntervalMillis: 500, // NOTE 500 milliseconds is less than our set time out, allowing for a sufficient cache reset before calling `fetchAndActivate()`
        })
      
  await fetchAndActivateCompare();   

}

This results in the following output in the console:

 LOG  Last fetch status:  success
 LOG  RemoteConfigs not fetched from fetch and then activate.
 LOG  RemoteConfigs fetched from fetchAndActivate.

Project Files

Javascript

Click To Expand

package.json:

# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
  'require.resolve(
    "react-native/scripts/react_native_pods.rb",
    {paths: [process.argv[1]]},
  )', __dir__]).strip

platform :ios, min_ios_version_supported
prepare_react_native_project!


flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabled

linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
  Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
  use_frameworks! :linkage => linkage.to_sym
end

target 'AOT' do
  config = use_native_modules!

  # Flags change depending on the env values.
  flags = get_default_flags()

  # Firebase needs to use frameworks see react-native-firebase docs
  use_frameworks! :linkage => :static
  $RNFirebaseAsStaticFramework = true

  use_react_native!(
    :path => config[:reactNativePath],
    # Hermes is now enabled by default. Disable by setting this flag to false.
    :hermes_enabled => flags[:hermes_enabled],
    :fabric_enabled => flags[:fabric_enabled],
    ## Enables Flipper.
    ##
    ## Note that if you have use_frameworks! enabled, Flipper will not work and
    ## you should disable the next line. (DISABLED FLIPPER FOR USE WITH FRAMEWORKS NEEDED FOR FIREBASE)
    # :flipper_configuration => flipper_config,
    ## An absolute path to your application root.
    :app_path => "#{Pod::Config.instance.installation_root}/.."
  )

  target 'AOTTests' do
    inherit! :complete
    # Pods for testing
  end


  post_install do |installer|

    # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
    react_native_post_install(
      installer,
      config[:reactNativePath],
      :mac_catalyst_enabled => false
    )
    __apply_Xcode_12_5_M1_post_install_workaround(installer)

  end
end

AppDelegate.mm:

#import "AppDelegate.h"
#import "RNBootSplash.h" // react-native-bootsplash
#import <Firebase.h> // Setup for Firebase services with react-native-firebase

#import <React/RCTBundleURLProvider.h>

// CUSTOM IMPORTS
#import <CodePush/CodePush.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure]; // Setup for Firebase services with react-native-firebase
  self.moduleName = @"AOT";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
  return [CodePush bundleURL]; // <--- Replaced for CodePush Previous: (return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];)
#endif
}

// 猬囷笍 This method will need to change for react-native-bootsplash to work on 0.74+ versions. See docs
- (UIView *)createRootViewWithBridge:(RCTBridge *)bridge
                          moduleName:(NSString *)moduleName
                           initProps:(NSDictionary *)initProps {
  UIView *rootView = [super createRootViewWithBridge:bridge moduleName:moduleName initProps:initProps];
  [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // 猬咃笍 initialize the splash screen (RN boot splash)
  return rootView;
}
// 猬嗭笍 This method will need to be removed and change to:
// - (void)customizeRootView:(RCTRootView *)rootView {
//   [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // 猬咃笍 initialize the splash screen
// }

@end


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

 System:
  OS: macOS 14.4
  CPU: (10) arm64 Apple M1 Pro
  Memory: 208.44 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.17.0
    path: ~/.nvm/versions/node/v18.17.0/bin/node
  Yarn:
    version: 1.22.21
    path: ~/.nvm/versions/node/v18.17.0/bin/yarn
  npm:
    version: 9.6.7
    path: ~/.nvm/versions/node/v18.17.0/bin/npm
  Watchman:
    version: 2023.09.25.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.13.0
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.1 AI-221.6008.13.2211.9619390
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.4
    wanted: 0.72.4
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • ^19.2.2
  • Firebase module(s) you're using that has the issue:
    • remote config
  • Are you using TypeScript?
    • Y & 5.0.4

@JDMathew JDMathew added Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report labels May 5, 2024
Copy link

github-actions bot commented Jun 2, 2024

Hello 馃憢, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@github-actions github-actions bot added the Type: Stale Issue has become stale - automatically added by Stale bot label Jun 2, 2024
@JDMathew
Copy link
Contributor Author

JDMathew commented Jun 3, 2024

Issue is still present

@github-actions github-actions bot removed the Type: Stale Issue has become stale - automatically added by Stale bot label Jun 3, 2024
@mikehardy
Copy link
Collaborator

Subtle one! Thanks for noting this and writing it up so well

When these methods were first implemented I'm not sure there was a way for us to test them well as it was difficult to update the remote configs and thus test update functionality

However, when the onConfigUpdated functionality for real-time remote config updates came in I added test infrastructure in form of a cloud function that updates our test app's remote config so I imagine this should be easy to probe now

Leaving this link as a breadcrumb to either myself or anyone else that wants to add an e2e test similar to probe the fetchAndActivate behavior https://github.com/invertase/react-native-firebase/pull/7119/files#diff-082cd0f3e3f8e1b47c7f2ec9b75d4bfd15ab6ca8b8d4baa64fd086ce2c058d73

@mikehardy mikehardy added Platform: iOS Service: Remote Config Firebase Remote Config Workflow: Needs Review Pending feedback or review from a maintainer. labels Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report Platform: iOS Service: Remote Config Firebase Remote Config Workflow: Needs Review Pending feedback or review from a maintainer.
Projects
None yet
Development

No branches or pull requests

2 participants