Repository navigation
fix(patches): register the live-markdown parser worklet in an insertion effect - #102415
Conversation
…on effect MarkdownTextInput registered its parser worklet during render and dropped the registration in an effect cleanup, which React runs without unmounting the component under StrictMode and for a hidden Activity. The native view then held a parser id that pointed at nothing and the input stopped formatting markdown. The patch carries Expensify/react-native-live-markdown#776 for 0.1.336: the id is chosen in JS per mounted input and registered in useInsertionEffect, and the native registry is a plain map that returns no ranges for an unknown id. The upstream PR is on hold until the library can rely on React Native 0.88; the insertion cleanup it depends on comes from the react-native patch in the previous commit.
The upstream PR now makes a parse for an id with no registered worklet log a warning and return no ranges without caching them, on both iOS and Android, instead of silently returning an empty result. The patch carries that change, which also touches apple/MarkdownParser.h and the Android MarkdownParser.java.
|
|
|
@dariusz-biela Could we add a test like |
Reviewer Checklist
Screenshots/VideosAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
The test renders the real MarkdownTextInput under StrictMode inside an <Activity> and records the native parser registry. The parser id the native view renders with stays registered after mount and across a hide and reveal, and an input removed while hidden unregisters it. The pre-patch shape, which registered during render and unregistered in an effect cleanup, fails all three cases.
|
@dariusz-biela The tests are failing. Could you check it? |
…e-markdown-parser-registration-patch
Codecov Report✅ All modified and coverable lines are covered by tests. |
|
All the GitHub Actions are now passing. If you have a moment, I'd appreciate it if you could finish the review. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.5.6-0 🚀
|
|
🚀 Deployed to production by https://github.com/puneetlath in version: 9.5.6-6 🚀
Bundle Size Analysis (Sentry): |



PR Stack
Follow-up to #101577, which fixed the React Native renderer so Fabric runs the insertion effect cleanup for a subtree removed while hidden. This PR carries the library change as a patch and relies on that renderer patch.
Explanation of Change
Patches
@expensify/react-native-live-markdown@0.1.336with the fix from Expensify/react-native-live-markdown#776: the parser worklet is registered inuseInsertionEffectinstead of during render, so the native input keeps formatting markdown after React remounts its effects. The upstream PR is on hold until the library can rely on React Native 0.88, which is why the change ships as a patch.In the app
MarkdownTextInputon iOS and Android keeps formatting markdown after its screen was hidden behind an<Activity>and shown again, and under StrictMode in development. Before, the input silently lost its parser and rendered plain text from then on.In the code
patches/@expensify/react-native-live-markdown/…+001+register-parser-worklet-in-insertion-effect.patchcarries thesrc/,lib/and native (cpp/,apple/,android/) parts of the upstream PR. The parser id is chosen in JS, one per mounted input and a fresh one on everyparserchange, and registered in a newuseParserIdhook. The native registry becomes a plain map from id to worklet. A parse for an id with no registered worklet logs a warning and returns no ranges without caching them, so the next parse picks the parser up once it is registered.patches/@expensify/react-native-live-markdown/details.mddocuments the patch and its dependency on the renderer patch from fix(patches): run the useInsertionEffect cleanup of a component removed inside a hidden Activity #101577: without it Fabric skips the insertion cleanup for an input removed while hidden and the worklet leaks in the native registry.Note
This case is unreachable in practice, but it is possible in theory, so I'm noting it here. On a
parserchange or unmount, the insertion cleanup unregisters the old id during the JS commit, a moment before the native view receives the newparserId. A parse that runs on the UI thread inside that window finds no worklet, logs aNo parser registeredwarning and returns no ranges for that single parse. The next parse formats the text again. I could not trigger it on the iOS simulator, even with fast typing right after a filter swap in the search router.Fixed Issues
$ #98254
PROPOSAL: N/A (internal fix)
Tests
The bug is latent on
main: no markdown input sits under a hidden<Activity>and StrictMode is off, so the dev steps turn on StrictMode, which disconnects and reconnects effects on every mount the same way a hidden<Activity>does. The patch changes native code, so rebuild the app afternpm install.npm installand verify that patch-package lists@expensify/react-native-live-markdown@0.1.336 (1 register-parser-worklet-in-insertion-effect)with a check mark and no warning.USE_REACT_STRICT_MODE_IN_DEVtotrueinsrc/CONFIG.ts, rebuild and start the app on iOS and Android. Open a report and typeHello *bold* _italic_ ~strike~ `code` https://expensify.comin the composer. Verify that every style and the link render as you type. Onmainwith the same flag the composer shows plain text only.*again*in the composer and verify that it renders bold.from:and pick a person from the suggestions. Verify that the filter is highlighted. Delete the picked value, pick a different person and verify that the new filter is highlighted too. Each change gives the input a new parser, so this checks that a parser swap keeps formatting.src/CONFIG.ts, run the app on web and repeat step 2. Verify that formatting works as before, since the web input is not part of the patch.Offline tests
N/A. The patch only changes when the markdown parser is registered on the native side, no network or Onyx code is involved.
QA Steps
Regression pass on the normal build, with no StrictMode and no
<Activity>. Run it on iOS and Android native, and steps 1 and 2 on mWeb and desktop web.Hello *bold* _italic_ ~strike~ `code` https://expensify.comin the composer. Add a code block, a quote (> quote), a heading (# heading), a mention of another member and an emoji. Verify that everything is formatted as you type.*bold*in the composer and verify that it renders bold.type:expense from:and pick a person from the suggestions. Verify that both filters are highlighted, then replace the picked person and verify that the highlighting follows.PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Dev tests (With React Strict Mode):
5-tests-android-markdown-formatting.mp4
QA tests (Without React Strict Mode):
6-qa-steps-android-markdown-formatting.mp4
iOS: Native
Dev tests (With React Strict Mode):
3-tests-ios-markdown-formatting.mp4
QA tests (Without React Strict Mode):
4-qa-steps-ios-markdown-formatting.mp4
MacOS: Chrome / Safari
Dev tests (With React Strict Mode):
1-tests-web-markdown-formatting.mp4
QA tests (Without React Strict Mode):
2-qa-steps-web-markdown-formatting.mp4