Skip to content

RN(View): Remove TextAncestor provider#29736

Closed
ecreeth wants to merge 1 commit into
facebook:masterfrom
ecreeth:remove-view-context
Closed

RN(View): Remove TextAncestor provider#29736
ecreeth wants to merge 1 commit into
facebook:masterfrom
ecreeth:remove-view-context

Conversation

@ecreeth
Copy link
Copy Markdown
Contributor

@ecreeth ecreeth commented Aug 23, 2020

Summary

I think the TextAncestor provider is unnecessary in the View component as the renderer
will throw an error if it doesn't find the value in the context anyway.

Changelog

[JavaScript] [Changed] - Remove TextAncestor provider for View

Test Plan

  • yarn test passed

  • RNTester Android app build successful

  • A View component with text must throw error: Text strings must be rendered within a <Text> component.

<View>Hello error</View>

Below we can see that all the providers of the View component have been eliminated from the component hierarchy

Before After
image image

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 23, 2020
@analysis-bot
Copy link
Copy Markdown

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,004,396 -84
android hermes armeabi-v7a 6,667,987 -87
android hermes x86 7,424,689 -90
android hermes x86_64 7,315,583 -101
android jsc arm64-v8a 9,164,319 -18
android jsc armeabi-v7a 8,820,026 -20
android jsc x86 9,012,705 -9
android jsc x86_64 9,589,784 -41

Base commit: b0fbbe5

@analysis-bot
Copy link
Copy Markdown

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: b0fbbe5

@elicwhite
Copy link
Copy Markdown
Member

Resetting the text ancestor is required to change what kinds of Text components render (inline text nodes, or block level text nodes). We need to reset that in View as text elements inside of a View need to reset to be a block level text, not an inline text node.

@elicwhite elicwhite closed this Aug 26, 2020
facebook-github-bot pushed a commit that referenced this pull request Mar 21, 2023
Summary:
Text need to know if is a descendant of a text in order to proper render nested text. For this react-native uses the textAncestor provider #29736 (comment).

This provides a not so ideal DX when profiling/Debugging as the view is polluted with TextAncestor.provider on each view render (As is the main render piece this happens quite often).

The idea behind of this PR is to just reset the context when view is a descendant of a text (Not so common case) rather than resetting all the time.

| Before  | After |
| ------------- | ------------- |
| ![Screenshot 2023-03-08 at 23 06 12](https://user-images.githubusercontent.com/6432326/226111157-d8af7990-2584-46b6-8f02-8583a84c2994.png)  |  ![Screenshot 2023-03-08 at 23 07 11](https://user-images.githubusercontent.com/6432326/226111222-65e8ac86-8ac8-4499-a725-c2f5ed2a2c99.png)  |

From my understanding of how hooks works this shouldn't degrade the performance and didn't spot any diff profiling my app (For better or worse).

## Changelog

[INTERNAL] [CHANGED] - Only reset textAncesor when is a child of text

Pull Request resolved: #36520

Test Plan: https://github.com/facebook/react-native/blob/main/packages/rn-tester/js/examples/Text/TextExample.ios.js

Reviewed By: necolas

Differential Revision: D44213843

Pulled By: javache

fbshipit-source-id: 246ac22557dc7794741fd9732d399fe8b9256f11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants