Repository navigation
fix(ai-components): use simple-markdown 0.7.3 to stop npm nesting React 18 under core - #3989
Merged
Merged
Conversation
…ct 18 under core
@khanacademy/simple-markdown peer-depends on react/react-dom ^18.2.0. In a
React 19 app installed with npm, npm satisfies that peer by nesting React
18.3.1 under stream-chat-react-native-core, so core imports a second React and
the app crashes at startup ("Cannot read property 'useState' of null").
Switch to the original simple-markdown 0.7.3, which the fork was cut from and
which has no peer dependencies. It is already in the tree through
react-native-markdown-package. Parsing and rendering are identical.
Contributor
SDK Size
|
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.
Ticket: https://linear.app/stream/issue/RN-485
🎯 Goal
Fix a startup crash for integrators who install with npm on React 19: "Cannot read property 'useState' of null".
Since 9.10.0, core depends on
@khanacademy/simple-markdown(^2.1.0) for the AI components' markdown. That package peer-depends onreact/react-dom^18.2.0. Core does not declarereactitself, so npm satisfies the peer by nesting React 18.3.1 atnode_modules/stream-chat-react-native-core/node_modules/react. Core's ownimport 'react'then resolves to that copy, and the app runs two Reacts.Only npm does this. Yarn 1, Yarn 4, pnpm 10 and bun 1.3 all hand core the app's React 19, which is why the monorepo never showed it.
🛠 Implementation details
Replace
@khanacademy/simple-markdownwith the originalsimple-markdown^0.7.3. The fork was cut from it at 0.8.0, and 0.7.3 has no peer dependencies. It is already in the tree throughreact-native-markdown-package, and core's main entry already imported it (renderText.tsx) without declaring it.package/package.json/yarn.lock: swap the dependency (the fork and@khanacademy/perseus-utilsdrop out).src/ai-components/markdown/*: import fromsimple-markdown. The API and type names are the same.bin/validate-entry-isolation.js: drop the fork from the AI-only packages list, since the main entry already usessimple-markdown.src/ai-components/README.md: point theruleslink at the original repo.The fork's newer releases don't help. Every version up to 4.0.3, and Perseus
main, still declaresreact/react-dom^18.2.0. 4.x is also ESM-only, so Metro on RN 0.76–0.78, which v9 still supports, can't resolve it.🎨 UI Changes
None. Markdown output is identical.
🧪 Testing
yarn lint,cd package && yarn test:typecheck,yarn buildandyarn test:unit(220 suites, 2421 tests) all pass.npm install --package-lock-onlynext toreact@19.3.0. Published 9.14.1 nestsreact/react-dom18.3.1 under core; the packed fix resolves a single React 19.3.0, with no@khanacademypackages.sanitizeUrland the defaulthroutput, and both are code we never run.☑️ Checklist
v9-releasebranch