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

[Documentation] Evolu (and Effect) require polyfills on React Native. #476

Open
samwightt opened this issue Sep 8, 2024 · 1 comment
Open

Comments

@samwightt
Copy link
Contributor

Evolu (and Effect, I think) both need polyfills in order to function in React Native when used with expo-router or Metro. Polyfills are needed for TextEncoder and TextDecoder, and for crypto.getRandomValues.

This can be fixed by installing expo-crypto and text-encoding, then writing a polyfill.ts like this:

import { polyfillGlobal } from "react-native/Libraries/Utilities/PolyfillFunctions"
import { TextEncoder, TextDecoder } from 'text-encoding'
import { getRandomValues } from 'expo-crypto'

polyfillGlobal("crypto", () => ({ getRandomValues}))
polyfillGlobal('TextEncoder', () => TextEncoder)
polyfillGlobal('TextDecoder', () => TextDecoder)

Then import polyfill.ts before any imports of Evolu.

Also note that in order to satisfy TS, you will need to make a react-native-polyfill.d.ts with the following content:

declare module 'react-native/Libraries/Utilities/PolyfillFunctions' {
    export function polyfillGlobal(name: string, getValue: () => any): void;
}

This should really be added to the documentation as part of the necessary setup in order to get things working with Expo or Metro.

@steida
Copy link
Contributor

steida commented Sep 9, 2024

I will review it after the new sync and update docs. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants