prisma / react-native-prisma

Apache License 2.0
174 stars 7 forks source link

react-native-quick-base64 breaks other libraries behaviour #13

Open sabaturgay opened 4 months ago

sabaturgay commented 4 months ago

Description

When integrating react-native-quick-base64, specifically importing and setting atob and btoa as global, there appears to be a conflict with @clerk/clerk-expo which relies on the default base64 encoding utilities. This issue arises because the global injection of atob and btoa overrides the expected behavior in other libraries which also depend on these utilities.

Steps to Reproduce

  1. Install react-native-quick-base64 and configure it as follows:

    
    import { atob, btoa } from 'react-native-quick-base64';
    
    global.atob = atob;
    global.btoa = btoa;
  2. Install @clerk/clerk-expo and observe issues in functionalities that depend on base64 encoding.

Error:

Error: Invalid string. Length must be a multiple of 4
    at getLens (address at /var/mobile/Containers/Data/Application/F617C86E-1588-452C-9C93-BD22FB351200/Library/Application Support/.expo-internal/bundle-bfa2bd90-21bb-433f-90f1-273c0f88a596.jsbundle:1:257721)
    at toByteArray (address at /var/mobile/Containers/Data/Application/F617C86E-1588-452C-9C93-BD22FB351200/Library/Application Support/.expo-internal/bundle-bfa2bd90-21bb-433f-90f1-273c0f88a596.jsbundle:1:257827)
    at toByteArray (address at /var/mobile/Containers/Data/Application/F617C86E-1588-452C-9C93-BD22FB351200/Library/Application Support/.expo-internal/bundle-bfa2bd90-21bb-433f-90f1-273c0f88a596.jsbundle:1:7703125)
    at atob (address at /var/mobile/Containers/Data/Application/F617C86E-1588-452C-9C93-BD22FB351200/Library/Application Support/.expo-internal/bundle-bfa2bd90-21bb-433f-90f1-273c0f88a596.jsbundle:1:7703468)
    at anonymous (address at /var/mobile/Containers/Data/Application/F617C86E-1588-452C-9C93-BD22FB351200/Library/<…>

Expected Behavior

The libraries should operate without interference in their handling of base64 encoding.

Actual Behavior

The global setting of atob and btoa interferes with @clerk/clerk-expo and potentially other libraries, leading to unexpected behaviors or failures in operations that rely on base64 encoding.

Suggested Solution

It would be beneficial for compatibility if we do not globally inject atob and btoa by default. Instead, allow developers to opt-in to this behavior in their own base code. This approach would prevent the override of native utilities unless explicitly desired by the developer, thereby reducing the risk of conflicts with other packages.

sorenbs commented 3 months ago

Thank you for investigating this Turgay!

I'm wondering if we could simply rely on the newly added atob and btoa functions in Hermes and RN 0.74.1 and avoid react-native-quick-base64 entirely. That would be much simpler.

Are you using Hermes and potentially able to verify that this works correctly with Clerk?

sabaturgay commented 3 months ago

It works in Hermes and RN 0.74.1. So I think we can disable atob and btoa injection.

sorenbs commented 3 months ago

Awesome - thanks for checking 🙌

So plan is to remove that injection, and return a helpful error if the app is running in an environment without native atob such as JavascriptCore or old Hermes.

I'll keep this issue open until that lands.