From 484f5780a658d29e5a8be5914ad78e6045d48a96 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Tue, 10 Dec 2024 09:26:01 +0100 Subject: [PATCH 1/3] Throw error when `html-entities` is not workletized --- example/ios/Podfile.lock | 8 ++++---- src/parseExpensiMark.ts | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index f3bb3529..aba22425 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1497,7 +1497,7 @@ PODS: - React-logger (= 0.75.3) - React-perflogger (= 0.75.3) - React-utils (= 0.75.3) - - RNLiveMarkdown (0.1.199): + - RNLiveMarkdown (0.1.203): - DoubleConversion - glog - hermes-engine @@ -1517,10 +1517,10 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - - RNLiveMarkdown/newarch (= 0.1.199) + - RNLiveMarkdown/newarch (= 0.1.203) - RNReanimated/worklets - Yoga - - RNLiveMarkdown/newarch (0.1.199): + - RNLiveMarkdown/newarch (0.1.203): - DoubleConversion - glog - hermes-engine @@ -1897,7 +1897,7 @@ SPEC CHECKSUMS: React-utils: f2afa6acd905ca2ce7bb8ffb4a22f7f8a12534e8 ReactCodegen: e35c23cdd36922f6d2990c6c1f1b022ade7ad74d ReactCommon: 289214026502e6a93484f4a46bcc0efa4f3f2864 - RNLiveMarkdown: 18dd4ceada29d66a6b7c29b1b0df589e2fc82183 + RNLiveMarkdown: ed779eaf35a346f5254079b825a13f0a032ba64a RNReanimated: ab6c33a61e90c4cbe5dbcbe65bd6c7cb3be167e6 SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: 1354c027ab07c7736f99a3bef16172d6f1b12b47 diff --git a/src/parseExpensiMark.ts b/src/parseExpensiMark.ts index 4162eb6c..d90078c8 100644 --- a/src/parseExpensiMark.ts +++ b/src/parseExpensiMark.ts @@ -2,8 +2,17 @@ import {ExpensiMark} from 'expensify-common'; import {unescapeText} from 'expensify-common/dist/utils'; +import {decode} from 'html-entities'; +import type {WorkletFunction} from 'react-native-reanimated/lib/typescript/commonTypes'; import type {MarkdownType, MarkdownRange} from './commonTypes'; +// eslint-disable-next-line no-underscore-dangle +if (__DEV__ && (decode as WorkletFunction).__workletHash === undefined) { + throw new Error( + "[react-native-live-markdown] `parseExpensiMark` requires `html-entities` package to be workletized. Please add `'worklet';` directive at the top of `node_modules/html-entities/lib/index.js` using patch-package.", + ); +} + const MAX_PARSABLE_LENGTH = 4000; type Token = ['TEXT' | 'HTML', string]; From 3890fad9b924e1cd700de21870db7d8c7bcfa1af Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Tue, 10 Dec 2024 09:34:11 +0100 Subject: [PATCH 2/3] Skip check on web and in Jest environment --- src/parseExpensiMark.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/parseExpensiMark.ts b/src/parseExpensiMark.ts index d90078c8..f4291eb3 100644 --- a/src/parseExpensiMark.ts +++ b/src/parseExpensiMark.ts @@ -1,13 +1,22 @@ 'worklet'; +import {Platform} from 'react-native'; import {ExpensiMark} from 'expensify-common'; import {unescapeText} from 'expensify-common/dist/utils'; import {decode} from 'html-entities'; import type {WorkletFunction} from 'react-native-reanimated/lib/typescript/commonTypes'; import type {MarkdownType, MarkdownRange} from './commonTypes'; +function isWeb() { + return Platform.OS === 'web'; +} + +function isJest() { + return !!process.env.JEST_WORKER_ID; +} + // eslint-disable-next-line no-underscore-dangle -if (__DEV__ && (decode as WorkletFunction).__workletHash === undefined) { +if (__DEV__ && !isWeb() && !isJest() && (decode as WorkletFunction).__workletHash === undefined) { throw new Error( "[react-native-live-markdown] `parseExpensiMark` requires `html-entities` package to be workletized. Please add `'worklet';` directive at the top of `node_modules/html-entities/lib/index.js` using patch-package.", ); From 8742eefe5f1a149561f6add61a9fb8936af9d313 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Tue, 10 Dec 2024 11:44:21 +0100 Subject: [PATCH 3/3] Fix E2E tests --- src/parseExpensiMark.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parseExpensiMark.ts b/src/parseExpensiMark.ts index f4291eb3..673734af 100644 --- a/src/parseExpensiMark.ts +++ b/src/parseExpensiMark.ts @@ -12,7 +12,7 @@ function isWeb() { } function isJest() { - return !!process.env.JEST_WORKER_ID; + return !!global.process.env.JEST_WORKER_ID; } // eslint-disable-next-line no-underscore-dangle