fix(patches): register the live-markdown parser worklet in an insertion effect - #102415
Draft
dariusz-biela wants to merge 3 commits into
Draft
dariusz-biela wants to merge 3 commits into
dariusz-biela wants to merge 3 commits into
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.
Contributor
|
|
40 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
iOS: Native
Dev tests:
3-tests-ios-markdown-formatting.mp4
QA tests:
4-qa-steps-ios-markdown-formatting.mp4
MacOS: Chrome / Safari
Dev tests:
1-tests-web-markdown-formatting.mp4
QA tests:
2-qa-steps-web-markdown-formatting.mp4