Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving feedback for "Text strings must be rendered within a <Text> component." errors. #20803

Closed
wants to merge 4 commits into from

Conversation

dmlux
Copy link

@dmlux dmlux commented Feb 11, 2021

Summary

This PR is meant to be a draft for changes in the renderer. In our company we sometimes facing "Text strings must be rendered within a <Text> component." errors related to conditional concatenation with components. Since conditionals are often values provided by services, it is difficult to track down the exact location where they occur. Unfortunately, both the error component stack and the call stack do not provide enough information to find the corresponding location in the code. For this reason, we patched React Native locally to drastically reduce the debugging time associated with such errors.

The provided changes of this PR are basically the patch applied locally to React Native in our project. The improvements to the messages from our patch include the actual text that could not be rendered, as well as a sibling component and its exact location in the source code. This allows my colleagues and me to quickly track down problems and locate the approximate point of failure in our code. It also gives a hint that the problem might be related to a concatenation between a value and a component.

However, this solution is not quite perfect, as the information is not detailed enough in cases where the error is caused by code, such as the following:

<View>
  forgot to wrap this text with text component...
</View>

Obviously, in this situation, there are no sibling components from which we can infer the source code location or parent component. Nevertheless, in such cases the message contains at least the text which could not be rendered without <Text> component. The question we have is whether it is possible to make the error message more verbose in all cases?

@facebook-github-bot
Copy link

Hi @dmlux!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@pke
Copy link

pke commented Feb 11, 2021

I wonder is there way to display additional information in the error box like a hint for the developer how to fix the error?

@sizebot
Copy link

sizebot commented Feb 11, 2021

Comparing: 483358c...5483801

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 = 122.34 kB 122.34 kB = 39.40 kB 39.40 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 128.92 kB 128.92 kB = 41.46 kB 41.46 kB
facebook-www/ReactDOM-prod.classic.js = 404.69 kB 404.69 kB = 75.17 kB 75.17 kB
facebook-www/ReactDOM-prod.modern.js = 393.04 kB 393.04 kB = 73.27 kB 73.27 kB
facebook-www/ReactDOMForked-prod.classic.js = 404.70 kB 404.70 kB = 75.17 kB 75.18 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
react-native/implementations/ReactNativeRenderer-prod.fb.js +0.40% 279.51 kB 280.62 kB +0.53% 50.08 kB 50.35 kB
react-native/implementations/ReactNativeRenderer-prod.js +0.40% 279.57 kB 280.68 kB +0.52% 50.11 kB 50.38 kB
react-native/implementations/ReactFabric-prod.fb.js +0.40% 272.08 kB 273.16 kB +0.50% 48.72 kB 48.97 kB
react-native/implementations/ReactFabric-prod.js +0.40% 272.13 kB 273.21 kB +0.50% 48.75 kB 48.99 kB
react-native/implementations/ReactNativeRenderer-profiling.fb.js +0.38% 292.17 kB 293.29 kB +0.50% 52.41 kB 52.67 kB
react-native/implementations/ReactNativeRenderer-profiling.js +0.38% 292.23 kB 293.35 kB +0.50% 52.44 kB 52.70 kB
react-native/implementations/ReactFabric-profiling.fb.js +0.38% 284.78 kB 285.85 kB +0.52% 51.06 kB 51.32 kB
react-native/implementations/ReactFabric-profiling.js +0.38% 284.83 kB 285.91 kB +0.52% 51.08 kB 51.35 kB

Generated by 🚫 dangerJS against 5483801

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@yungsters
Copy link
Contributor

I previously attempted this in #19581, but I reverted it in #19723 because of feedback that I received (from @sebmarkbage, IIRC) around security implications of logging arbitrarily user-generated content.

@stale
Copy link

stale bot commented Jun 11, 2021

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.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jun 11, 2021
@pke
Copy link

pke commented Jun 11, 2021

Commenting to keep this PR open. Would be nice to improve the developer experience with that PR

@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Jun 11, 2021
@stale
Copy link

stale bot commented Jan 9, 2022

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.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 9, 2022
@yungsters
Copy link
Contributor

There is another open PR that I just commented on last week to do this.

@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Jan 9, 2022
@yungsters
Copy link
Contributor

yungsters commented Jan 9, 2022

See #22725.

@sebmarkbage sebmarkbage deleted the branch facebook:master October 20, 2022 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants