Skip to content

Commit f10e7fc

Browse files
committed
Use a constant HostContext in prod builds
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`.
1 parent fb57fc5 commit f10e7fc

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)