@samitouri / QOS-React-2 / commits / 3154ec8a38

Use a constant HostContext in prod builds for Fabric renderer (#29888)

<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory. Before submitting a pull request, please make sure the following is done: 1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`. 2. Run `yarn` in the repository root. 3. If you've fixed a bug or added code that should be tested, add tests! 4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development. 5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`. 6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect". 7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`). 8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files. 9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`). 10. If you haven't already, complete the CLA. Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html --> ## Summary <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? --> In the Fabric renderer in React Native, we only use the HostContext to issue soft errors in __DEV__ bundles when attempting to add a raw text child to a node that may not support them. Moving the logic to set this context to __DEV__ bundles only unblocks more expensive methods for resolving whether a parent context supports raw text children, like resolving this information from `getViewConfigForType`. ## How did you test this change? <!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface. How exactly did you verify that your PR solves the issue you wanted to solve? If you leave this empty, your PR will very likely be closed. --> yarn test (--prod)

Eric Rozell committed Jun 14, 2024 at 13:37 UTC 3154ec8a38e6014090039be54e0ca597fa967fdd
1 file changed +24 -16
packages/react-native-renderer/src/ReactFiberConfigFabric.js
+24 -16
@@ -132,6 +132,8 @@ export function appendInitialChild(
132 appendChildNode(parentInstance.node, child.node);
133 }
134
135 +const PROD_HOST_CONTEXT: HostContext = {isInAParentText: true};
136 +
137 export function createInstance(
138 type: string,
139 props: Props,
@@ -220,29 +222,35 @@ export function finalizeInitialChildren(
222 export function getRootHostContext(
223 rootContainerInstance: Container,
224 ): HostContext {
223 - return {isInAParentText: false};
225 + if (__DEV__) {
226 + return {isInAParentText: false};
227 + }
228 +
229 + return PROD_HOST_CONTEXT;
230 }
231
232 export function getChildHostContext(
233 parentHostContext: HostContext,
234 type: string,
235 ): HostContext {
230 - const prevIsInAParentText = parentHostContext.isInAParentText;
231 - const isInAParentText =
232 - type === 'AndroidTextInput' || // Android
233 - type === 'RCTMultilineTextInputView' || // iOS
234 - type === 'RCTSinglelineTextInputView' || // iOS
235 - type === 'RCTText' ||
236 - type === 'RCTVirtualText';
237 -
238 - // TODO: If this is an offscreen host container, we should reuse the
239 - // parent context.
240 -
241 - if (prevIsInAParentText !== isInAParentText) {
242 - return {isInAParentText};
243 - } else {
244 - return parentHostContext;
236 + if (__DEV__) {
237 + const prevIsInAParentText = parentHostContext.isInAParentText;
238 + const isInAParentText =
239 + type === 'AndroidTextInput' || // Android
240 + type === 'RCTMultilineTextInputView' || // iOS
241 + type === 'RCTSinglelineTextInputView' || // iOS
242 + type === 'RCTText' ||
243 + type === 'RCTVirtualText';
244 +
245 + // TODO: If this is an offscreen host container, we should reuse the
246 + // parent context.
247 +
248 + if (prevIsInAParentText !== isInAParentText) {
249 + return {isInAParentText};
250 + }
251 }
252 +
253 + return parentHostContext;
254 }
255
256 export function getPublicInstance(instance: Instance): null | PublicInstance {