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

Android crash when unmounting PaywallFooterContainerView: java.lang.IllegalStateException: No ViewModelStoreOwner was provided via LocalViewModelStoreOwner #994

Open
5 tasks done
carter-0 opened this issue May 2, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@carter-0
Copy link

carter-0 commented May 2, 2024

Describe the bug

When unmounting the RevenueCatUI.PaywallFooterContainerView on Android devices, java.lang.IllegalStateException: No ViewModelStoreOwner was provided via LocalViewModelStoreOwner is thrown.

  1. Environment
    1. Platform: Android only
    2. SDK version: 7.27.1 (both react-native-purchases and react-native-purchases-ui)
    3. OS version: Clip is on Android 10, but bug is on all versions.
    4. Xcode/Android Studio version: idk
    5. React Native version: 0.73.6
    6. SDK installation (CocoaPods + version or manual): expo
    7. How widespread is the issue. Percentage of devices affected: 100%
  2. Debug logs that reproduce the issue:
 ERROR  Your app just crashed. See the error below.
java.lang.IllegalStateException: No ViewModelStoreOwner was provided via LocalViewModelStoreOwner
    at com.revenuecat.purchases.ui.revenuecatui.InternalPaywallKt.getPaywallViewModel(InternalPaywall.kt:301)
    at com.revenuecat.purchases.ui.revenuecatui.InternalPaywallKt.InternalPaywall(InternalPaywall.kt:58)
    at com.revenuecat.purchases.ui.revenuecatui.PaywallKt.Paywall(Paywall.kt:12)
    at com.revenuecat.purchases.ui.revenuecatui.PaywallFooterKt$PaywallFooter$paywallComposable$1.invoke(PaywallFooter.kt:36)
    at com.revenuecat.purchases.ui.revenuecatui.PaywallFooterKt$PaywallFooter$paywallComposable$1.invoke(PaywallFooter.kt:35)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
    at com.revenuecat.purchases.ui.revenuecatui.PaywallFooterKt.PaywallFooter(PaywallFooter.kt:45)
    at com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView$init$2$1.invoke(PaywallFooterView.kt:132)
    at com.revenuecat.purchases.ui.revenuecatui.views.PaywallFooterView$init$2$1.invoke(PaywallFooterView.kt:128)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
    at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:428)
    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:252)
    at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:251)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:195)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:119)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:118)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:110)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:158)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:157)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
    at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:157)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:142)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
    at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
    at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
    at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3340)
    at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3273)
    at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:588)
    at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:1013)
    at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:520)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:142)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
    at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1191)
    at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:133)
    at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:183)
    at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
    at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.kt:192)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
    at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
    at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1191)
    at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:133)
    at androidx.compose.ui.platform.Wrapper_androidKt.doSetContent(Wrapper.android.kt:104)
    at androidx.compose.ui.platform.Wrapper_androidKt.setContent(Wrapper.android.kt:83)
    at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:251)
    at androidx.compose.ui.platform.AbstractComposeView.onMeasure(ComposeView.android.kt:288)
    at android.view.View.measure(View.java:24723)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6903)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at com.revenuecat.purchases.react.ui.PaywallFooterViewManager$createViewInstance$1.onMeasure(PaywallFooterViewManager.kt:40)
    at android.view.View.measure(View.java:24723)
    at com.revenuecat.purchases.react.ui.PaywallFooterViewManager$createViewInstance$1.measureAndLayout$lambda$0(PaywallFooterViewManager.kt:28)
    at com.revenuecat.purchases.react.ui.PaywallFooterViewManager$createViewInstance$1.$r8$lambda$ov1FIeRAm44dBT08dD92Nth7RB0
    at com.revenuecat.purchases.react.ui.PaywallFooterViewManager$createViewInstance$1$$ExternalSyntheticLambda1.run
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7386)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
  1. Steps to reproduce, with a description of expected vs. actual behavior:
  • Create this component:
import {useState} from 'react';
import {Text, Switch} from 'react-native';
import RevenueCatUI from 'react-native-purchases-ui';

export default function PaywallExample() {
    const [isOpen, setIsOpen] = useState(false);

    return (
        <>
            <Switch onChange={() => setIsOpen(!isOpen)} value={isOpen} />

            {isOpen ? (
                <>
                    <RevenueCatUI.PaywallFooterContainerView>
                        <Text>Footer Content</Text>
                    </RevenueCatUI.PaywallFooterContainerView>
                </>
            ) : null}
        </>
    )
}
  • Open paywall with switch
  • Close paywall with switch

Expected behaviour: Paywall footer will be shown and then hidden without any issues
Actual behaviour: Paywall footer is shown succesfully but crashes when unmounted.

Here is a video demonstration of the expected behaviour (on iOS) vs the actual behaviour (on Android) with the exact same code:

8mb.video-7Gv-j6y8b5cE.mp4
@carter-0 carter-0 added the bug Something isn't working label May 2, 2024
@RCGitBot
Copy link
Contributor

RCGitBot commented May 2, 2024

👀 We've just linked this issue to our internal tracker and notified the team. Thank you for reporting, we're checking this out!

@michaelAtRC
Copy link

Hey @carter-0 !

Thanks for reaching out, this error usually happens when LocalViewModelStoreOwner.current is set to null. Can you please verify that this doesn't get set to null, it could be because of something like a rerender being triggered by your code. This could be the result of something in your switch case causing an issue or the state not being re-rendered properly.

Let me know if that helps!

@carter-0
Copy link
Author

carter-0 commented May 6, 2024

@michaelAtRC Thanks for the response but I can't figure out how to check this. Is LocalViewModelStoreOwner not a Kotlin native component handled by react-native-purchases-ui? or is there a way to access this from react native?

Sorry for the ignorance, I'm pretty new to react native & app development😅

@Watersdr
Copy link

I'm experiencing this crash as well. Dismissing the paywall footer on Android causes the app to crash every time

@Watersdr
Copy link

For what it's worth, I'm not using any custom UI with my footer. I'm simply displaying it inside a BottomSheet. @carter-0 I was able to stop this crash from happening by commenting out this line:

This is fine for my use-case because my view isn't ever updating since I'm not using custom UI with my footer, which is the purpose of that call. The crash is 100% happening somewhere inside the onMeasure call within PaywallFooterViewManager.kt but I don't have time to track down the cause right now.

I think I'll just have to patch the library to comment that line to get my app working properly.

@carter-0
Copy link
Author

Thanks @Watersdr, I can confirm commenting that line out also fixes the crash for me, even with custom ui in the footer. I haven't noticed any other effects so far so I'm also going to patch the lib as a temporary fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants