fix: install TextEncoder/TextDecoder polyfills before protobufjs loads
protobufjs v8 reads TextDecoder at import time, and Hermes does not provide it. The polyfill assignment in index.js ran after hoisted imports, so the app crashed on launch with 'Property TextDecoder doesn't exist'. Move the polyfills into their own module imported first so they are installed before any other module executes.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import './polyfills';
|
||||
import 'react-native-gesture-handler';
|
||||
import { enableScreens } from 'react-native-screens';
|
||||
enableScreens();
|
||||
@@ -11,19 +12,9 @@ enableScreens();
|
||||
import 'react-native-get-random-values';
|
||||
import 'react-native-url-polyfill/auto';
|
||||
import 'message-port-polyfill';
|
||||
const TextEncodingPolyfill = require("text-encoding");
|
||||
import Long from 'long';
|
||||
import protobuf from 'protobufjs';
|
||||
|
||||
const applyGlobalPolyfills = () => {
|
||||
Object.assign(global, {
|
||||
TextEncoder: TextEncodingPolyfill.TextEncoder,
|
||||
TextDecoder: TextEncodingPolyfill.TextDecoder,
|
||||
});
|
||||
};
|
||||
|
||||
applyGlobalPolyfills();
|
||||
|
||||
protobuf.util.Long = Long;
|
||||
protobuf.configure();
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// Global polyfills that must be installed before any other module loads.
|
||||
// Hermes has no TextEncoder/TextDecoder, and protobufjs v8+ reads
|
||||
// TextDecoder at import time, so this module must be the first import
|
||||
// in index.js — imports are hoisted, so assigning these globals from
|
||||
// index.js's own body runs too late.
|
||||
const TextEncodingPolyfill = require('text-encoding');
|
||||
|
||||
if (typeof global.TextEncoder === 'undefined') {
|
||||
global.TextEncoder = TextEncodingPolyfill.TextEncoder;
|
||||
}
|
||||
if (typeof global.TextDecoder === 'undefined') {
|
||||
global.TextDecoder = TextEncodingPolyfill.TextDecoder;
|
||||
}
|
||||
Reference in New Issue
Block a user