hermes icon indicating copy to clipboard operation
hermes copied to clipboard

using TextDecoder with hermes

Open davidliu opened this issue 1 year ago • 4 comments

Problem

TextEncoder was recently added with 3863a36a53005dd1e6d39ea0d4ef5573bafde910 (related issue #948), but there doesn't seem to be a TextDecoder added. It seems odd that the encoder was added without the related decoder.

Solution

Add TextDecoder to hermes.

davidliu avatar May 22 '24 02:05 davidliu

Hi, is this planned?

Badbird5907 avatar Aug 11 '24 07:08 Badbird5907

It is planned, but not very high priority. PRs are welcome.

tmikov avatar Aug 11 '24 16:08 tmikov

hi @tmikov is there a plan to release a TextDecoder?

gituser8796 avatar Aug 17 '24 20:08 gituser8796

Having this issue in react-native 0.74. Workaround is to use import 'fast-text-encoder in every layout which uses an import which deals with TextDecoder.

Is there a fix for this in the near future? I have seen the cpp code for TextEncoder and there is no way for me to contribute to this with my knowledge of cpp. I'm using Effect HttpClient which uses TextDecoder.

mabasic avatar Sep 15 '24 20:09 mabasic

Eagerly awaiting for TextDecoder 🧘

aretrace avatar Sep 29 '24 21:09 aretrace

hi @tmikov do we know when it will be in?

gituser8796 avatar Oct 03 '24 13:10 gituser8796

I'm also waiting for this :/ Does anybody know how to find out which package depends on TextDecoder? I only get this error here:

ReferenceError: Property 'TextDecoder' doesn't exist, js engine: hermes

I don't know where it comes from 🙈

heybuild avatar Oct 07 '24 19:10 heybuild

@heybuild You have two options to polyfill the TextDecoder API:

  • https://github.com/inexorabletash/text-encoding
  • https://github.com/maksimlya/react-native-fast-encoder

I've written a short guide on how to use one of them to enable streaming in React Native (Expo): 👉 https://gist.github.com/aretrace/bcb0777c2cfd2b0b1d9dcfb805fe2838

aretrace avatar Oct 07 '24 22:10 aretrace

@heybuild You have two options to polyfill the TextDecoder API:

  • https://github.com/inexorabletash/text-encoding
  • https://github.com/maksimlya/react-native-fast-encoder

I've written a short guide on how to use one of them to enable streaming in React Native (Expo): 👉 https://gist.github.com/aretrace/bcb0777c2cfd2b0b1d9dcfb805fe2838

Thank you! This did the trick:

// index.ts
import "fast-text-encoding";
import "expo-router/entry";

heybuild avatar Oct 09 '24 16:10 heybuild

You have two options to polyfill the TextDecoder API:

Hi @aretrace , I have the same TextDecoder issue. When I use TextDecoder('latin1') in my ReactNative code, it causes error: Unknown encoding: latin1. I tried to polyfill using react-native-fast-encoder and fast-text-encoding in my App.ts, but it didn't work.

if (typeof global.TextEncoder === 'undefined') {
  global.TextEncoder = TextEncoder
}
if (typeof global.TextDecoder === 'undefined') {
  global.TextDecoder = TextDecoder
}

I did not use the TextDecode directly in my own code, it's a thirdparty library I dependent use TextDecode. Should I modify the thirdparty library, do the polyfill?

andy380743909 avatar Aug 12 '25 07:08 andy380743909