Repository navigation
fix(ai-components): use simple-markdown 0.7.3 to stop npm nesting React 18 under core - #3988
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.
2 of 6 tasks
Contributor
SDK Size
|
isekovanic
added a commit
that referenced
this pull request
Nov 12, 2026
β¦ct 18 under core (#3989) 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 on `react`/`react-dom` `^18.2.0`. Core does not declare `react` itself, so npm satisfies the peer by nesting React 18.3.1 at `node_modules/stream-chat-react-native-core/node_modules/react`. Core's own `import '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-markdown` with the original `simple-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 through `react-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-utils` drop out). - `src/ai-components/markdown/*`: import from `simple-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 uses `simple-markdown`. - `src/ai-components/README.md`: point the `rules` link at the original repo. The fork's newer releases don't help. Every version up to 4.0.3, and Perseus `main`, still declares `react`/`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 build` and `yarn test:unit` (220 suites, 2421 tests) all pass. - npm proof: `npm install --package-lock-only` next to `react@19.3.0`. Published 9.14.1 nests `react`/`react-dom` 18.3.1 under core; the packed fix resolves a single React 19.3.0, with no `@khanacademy` packages. - Parity between the fork (2.2.3) and 0.7.3, run through our AI markdown rules on 2,732 markdown files: the parse trees and rendered element trees are identical. A source diff confirms the parser and regex code is the same. The only differences are `sanitizeUrl` and the default `hr` output, and both are code we never run. - On device: checked on the V10 PR, #3988. The markdown code differs slightly on v9, so the 2,732-file parity check was re-run here too, with identical results. ## βοΈ Checklist - [ ] I have signed the [Stream CLA](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) (required) - [x] PR targets the `v9-release` branch - [x] Documentation is updated - [ ] New code is tested in main example apps, including all possible scenarios - [ ] SampleApp iOS and Android - [ ] Expo iOS and Android
|
π This PR is included in version 10.1.0 π The release is available on:
Your semantic-release bot π¦π |
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. Even though V10 can resolve ESM modules just fine, some changes still need to be made to the upstream library so thatreact-domis no longer enforced. For the time being, we'll revert to the known library that enforces nothing and we'll take up the markdown topic more seriously in the near future.π¨ UI Changes
None. Markdown output is identical.
π§ͺ Testing
yarn lint,cd package && yarn test:typecheck,yarn buildandyarn test:unit(272 suites, 3206 tests) all pass.npm install --package-lock-onlynext toreact@19.3.0. Published 10.0.2 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
developbranch