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

[BUG] Error in React Native project after the update to 3.0.0 #232

Closed
1 task done
mlazari opened this issue Jan 25, 2024 · 6 comments
Closed
1 task done

[BUG] Error in React Native project after the update to 3.0.0 #232

mlazari opened this issue Jan 25, 2024 · 6 comments
Labels
acknowledged bug Something isn't working

Comments

@mlazari
Copy link

mlazari commented Jan 25, 2024

Is there an existing issue for this?

  • I have searched the existing issues

SDK Version

3.0.0

Current Behavior

Error:

 WARN  [OPTIMIZELY] - ERROR 2024-01-25T09:42:46.596Z BUCKETER: Unable to generate hash for bucketing ID 10...80: Property 'TextEncoder' doesn't exist

Expected Behavior

No errors.

Steps To Reproduce

Version 3.0.0 updated @optimizely/optimizely-sdk from 4.9.1 to 5.0.0 (2.9.2...3.0.0#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519L33), that updated murmurhash to 2.0.1 and that replaced Buffer with TextEncoder (https://github.com/perezd/node-murmurhash/releases/tag/2.0.1). The problem is that TextEncoder doesn't seem to be defined in ReactNative environment (maybe just when using hermes engine?) so it throws errors like this:

 WARN  [OPTIMIZELY] - ERROR 2024-01-25T09:42:46.596Z BUCKETER: Unable to generate hash for bucketing ID 10...80: Property 'TextEncoder' doesn't exist

I found this in another repo - paralleldrive/cuid2#41 - which seems to be addressed here by adding instructions to the README - paralleldrive/cuid2@21da5b4. Should this library also have that documented maybe? I tried adding those polyfills and both of them fix the issue.

React Framework

No response

Browsers impacted

No response

Link

No response

Logs

No response

Severity

No response

Workaround/Solution

Use either fast-text-encoding or text-encoding-polyfill TextEncoder polyfill as mentioned in paralleldrive/cuid2@21da5b4

Recent Change

No response

Conflicts

No response

@mikechu-optimizely
Copy link
Contributor

We're testing this under internal ticket FSSDK-10089 this week.

@mikechu-optimizely
Copy link
Contributor

We're still seeing this as a problem in React Native projects... More research needed...

@mikechu-optimizely
Copy link
Contributor

Also reported by optimizely/javascript-sdk#925

@junaed-optimizely
Copy link
Contributor

@mlazari you are right. TextEncoder was not available in Hermes until recently. So React Native >= 0.74 now supports TextEncoder. Upgrading to >=0.74 will resolve the issue.
If the upgrade is not possible, then you have to use polyfill to support the encoding functionalities. Here is one you can try.

@mlazari
Copy link
Author

mlazari commented Jun 24, 2024

@junaed-optimizely Thank you, good to know 0.74 supports it. For now I ended up using fast-text-encoding. text-encoding-polyfill also was working when I tried it, as I mentioned in the description.

@junaed-optimizely
Copy link
Contributor

Closing this, as we have added better support for React Native in v3.1.2 onward. And here is the detailed doc for integration. React Native installation guide

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

No branches or pull requests

3 participants