Skip to content

Commit 3154ec8

Browse files
authored
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)
1 parent f0e8164 commit 3154ec8

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

packages/react-native-renderer/src/ReactFiberConfigFabric.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ export function appendInitialChild(
132132
appendChildNode(parentInstance.node, child.node);
133133
}
134134

135+
const PROD_HOST_CONTEXT: HostContext = {isInAParentText: true};
136+
135137
export function createInstance(
136138
type: string,
137139
props: Props,
@@ -220,29 +222,35 @@ export function finalizeInitialChildren(
220222
export function getRootHostContext(
221223
rootContainerInstance: Container,
222224
): HostContext {
223-
return {isInAParentText: false};
225+
if (__DEV__) {
226+
return {isInAParentText: false};
227+
}
228+
229+
return PROD_HOST_CONTEXT;
224230
}
225231

226232
export function getChildHostContext(
227233
parentHostContext: HostContext,
228234
type: string,
229235
): 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+
}
245251
}
252+
253+
return parentHostContext;
246254
}
247255

248256
export function getPublicInstance(instance: Instance): null | PublicInstance {

0 commit comments

Comments
 (0)