react icon indicating copy to clipboard operation
react copied to clipboard

Allow third-party react-native libraries to render text

Open fabOnReact opened this issue 1 year ago • 1 comments

Summary

It is not possible to publish a third-party library Text/TextInput component that accepts raw text as children. The function createTextInstance triggers an error if the name of the HostComponent is not one of those defined in getChildHostComponent.

This PR adds one additional type to the react-native renderer to be used by third-party libraries (fixes https://github.com/facebook/react-native/issues/25136).

Additional info on the motivations for this change

The react-native team previously suggested publishing react-native patches for Text and TextInput through a third-party library (https://github.com/react-native-community/discussions-and-proposals/discussions/731#discussioncomment-7821826).

The library react-native-improved provides react-native bug fixes without using patch-package or forking react-native.

The project is currently a proof of concept and applies only one fix (PR https://github.com/facebook/react-native/pull/41770) to the react-native Text component, but more components and fixes could be published in the future.

The advantages of this approach over forking react-native are the following:

  • The components are based on the react-native implementation (for ex. ReactTextView, ReactTextViewManager, and ReactTextShadowNode).
  • It is possible to add javascript, android and iOS patches
  • No issues upgrading react-native
  • The fixes can be used selectively in the application (for ex. by using import { TextImproved } from 'react-native-improved')
  • Allows a wider community to contribute to react-native
  • May help make the release process of react-native easier in the future
  • Fast development workflow (building react-native from source with third party libraries may take 10-30 minutes)

How did you test this change?

  • I tested the solution with patch-package in the react-native-improved example
  • I tested the solution in a brand new react-native 0.73 app after installing react-native-improved npm package
Before After

fabOnReact avatar Dec 13 '23 09:12 fabOnReact

Comparing: 493610f299ddf7d06e147e60dc4f2b97482982d2...5600bae73109af33cd75e5167e4665ed0767d4ea

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 175.90 kB 175.90 kB = 54.76 kB 54.75 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 177.97 kB 177.97 kB = 55.39 kB 55.39 kB
facebook-www/ReactDOM-prod.classic.js = 570.21 kB 570.21 kB = 100.35 kB 100.35 kB
facebook-www/ReactDOM-prod.modern.js = 554.06 kB 554.06 kB = 97.43 kB 97.43 kB
test_utils/ReactAllWarnings.js Deleted 67.41 kB 0.00 kB Deleted 16.49 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
test_utils/ReactAllWarnings.js Deleted 67.41 kB 0.00 kB Deleted 16.49 kB 0.00 kB

Generated by :no_entry_sign: dangerJS against 5600bae73109af33cd75e5167e4665ed0767d4ea

react-sizebot avatar Dec 13 '23 09:12 react-sizebot

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

github-actions[bot] avatar Apr 05 '24 02:04 github-actions[bot]

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

github-actions[bot] avatar Apr 12 '24 15:04 github-actions[bot]