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

Added more context to invalid text string errors #22725

Conversation

EvanBacon
Copy link

Summary

This PR is a companion to facebook/react-native#32544 which was recommended here facebook/react-native#32544 (comment). In React Native, the stack traces shown in LogBox often just point to fast refresh and don't provide much context into cases where a user adds a string outside of a Text element, this PR improves discoverability a little by adding the invalid text to the error message.

How did you test this change?

Update the error message format to include the invalid text string.

@EvanBacon EvanBacon marked this pull request as ready for review November 8, 2021 21:27
@sizebot
Copy link

sizebot commented Nov 8, 2021

Comparing: 2db6d6a...871c7c7

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 = 129.55 kB 129.55 kB = 41.43 kB 41.43 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 134.52 kB 134.52 kB = 42.89 kB 42.90 kB
facebook-www/ReactDOM-prod.classic.js = 423.36 kB 423.36 kB = 78.05 kB 78.05 kB
facebook-www/ReactDOM-prod.modern.js = 411.92 kB 411.92 kB = 76.30 kB 76.30 kB
facebook-www/ReactDOMForked-prod.classic.js = 423.36 kB 423.36 kB = 78.06 kB 78.06 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 871c7c7

@yungsters
Copy link
Contributor

Thanks again for your contribution, @EvanBacon.

I'll copy over some of my feedback from facebook/react-native#32544:

tl;dr — I previously attempted a similar change, but was recommended to revert it because @acdlite and @sebmarkbage raised concerns with logging arbitrary strings which may be sensitive (e.g. passwords, banking information).

@EvanBacon — What do you think about only appending the string if an opt-in flag is set (e.g. global.debugInvalidTextStrings), and then changing the error message to inform people to do that to opt into the extra error text? (And maybe when the opt-in flag is set, remind them to remove it when they're done debugging.)

It looks like the current status of this PR does not incorporate an opt-in flag as I previously suggested. Does this PR simply need to be updated, or do you have concerns about that approach?

@gaearon
Copy link
Collaborator

gaearon commented Jan 11, 2022

Is there some other kind of information we could add other than the text itself? Options don't seem ideal for this.

Unfortunately, both the error component stack and the call stack do not provide enough information to find the corresponding location in the code.

Is there a longer elaboration on why component stack does not provide enough information? Any concrete case I can look at?

@EvanBacon
Copy link
Author

EvanBacon commented Jan 11, 2022

@gaearon perhaps the most minimal repro in native:

blank.zip

Setup

  • yarn
  • yarn start
  • Press i or a (opens in Expo Go)

Code

App.js

import { View } from "react-native";

export default function App() {
  return (
    <View
      style={{
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
      }}>
      Hey
    </View>
  );
}

Error Output

Error: Text strings must be rendered within a <Text> component.

This error is located at:
    in RCTView (at View.js:34)
    in View (created by App)
    in App (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:47)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:107)
    in DevAppContainer (at AppContainer.js:122)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:134)
    in AppContainer (at renderApplication.js:40)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/ReactFiberErrorDialog.js:43:2 in showErrorDialog
at node_modules/react-native/Libraries/Core/setUpReactRefresh.js:43:6 in performReactRefresh
at node_modules/metro-runtime/src/polyfills/require.js:655:10 in <unknown>

Error: Text strings must be rendered within a <Text> component.

This error is located at:
    in RCTView (at View.js:34)
    in View (created by App)
    in App (created by ExpoRoot)
    in ExpoRoot (at renderApplication.js:47)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:107)
    in DevAppContainer (at AppContainer.js:122)
    in RCTView (at View.js:34)
    in View (at AppContainer.js:134)
    in AppContainer (at renderApplication.js:40)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/expo-error-recovery/build/ErrorRecovery.fx.js:12:21 in <unknown>

Initial Load

Fast Refresh

EvanBacon added a commit to expo/expo that referenced this pull request Feb 3, 2023
# Why

- Temporary workaround for facebook/react#22725
- Unwrapped text strings are very difficult to find and cause critical
errors to occur. When using expo/html-elements, devs have a much higher
chance of accidentally making this mistake.
- `@expo/html-elements` is web-first React Native and therefore should
have first-class types and styles for `react-native-web`. This PR
injects a native wrapper to strip out web styles that aren't supported.

# How

When a text child appears in View, the child is replaced by a red view
with text indicating the string. A warning is also presented to attempt
to provide a stack trace (which mostly doesn't help).

# Test Plan

- Added unit tests for the expected functionality.
- I've been using this in my personal package `@bacons/react-views` for
a while and it hurts to go back.

<!--
Please describe how you tested this change and how a reviewer could
reproduce your test, especially if this PR does not include automated
tests! If possible, please also provide terminal output and/or
screenshots demonstrating your test/reproduction.
-->

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `expo prebuild` & EAS Build (eg:
updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Copy link

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.

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Copy link

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

@github-actions github-actions bot closed this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants