GeezerVison is showing github.com — Improve DEV errors if string coercion throws (Temporal.*, Symbol, etc… · react/react@c88fb49
File treeExpand file treeCollapse file tree Open diff view settings fixtures/dom/src/components/fixtures/error-handling react-debug-tools/src/__tests__ react-devtools-extensions/src react-devtools-shared/src
Some content is hiddenLarge Commits have some content hidden by default. Use the searchbox below for content that may be hidden. Dismiss bannerExpand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +12-1Lines changed: 12 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -108,6 +108,10 @@ module.exports = { | 108 | 108 | // CUSTOM RULES | 109 | 109 | // the second argument of warning/invariant should be a literal string | 110 | 110 | 'react-internal/no-primitive-constructors': ERROR, | | 111 | + 'react-internal/safe-string-coercion': [ | | 112 | + ERROR, | | 113 | + {isProductionUserAppCode: true}, | | 114 | + ], | 111 | 115 | 'react-internal/no-to-warn-dev-within-to-throw': ERROR, | 112 | 116 | 'react-internal/invariant-args': ERROR, | 113 | 117 | 'react-internal/warning-args': ERROR, | @@ -168,10 +172,17 @@ module.exports = { | 168 | 172 | 'packages/*/npm/**/*.js', | 169 | 173 | 'packages/dom-event-testing-library/**/*.js', | 170 | 174 | 'packages/react-devtools*/**/*.js', | | 175 | + 'dangerfile.js', | | 176 | + 'fixtures', | | 177 | + 'packages/react-dom/src/test-utils/*.js', | 171 | 178 | ], | 172 | 179 | rules: { | 173 | 180 | 'react-internal/no-production-logging': OFF, | 174 | 181 | 'react-internal/warning-args': OFF, | | 182 | + 'react-internal/safe-string-coercion': [ | | 183 | + ERROR, | | 184 | + {isProductionUserAppCode: false}, | | 185 | + ], | 175 | 186 |
| 176 | 187 | // Disable accessibility checks | 177 | 188 | 'jsx-a11y/aria-role': OFF, | @@ -185,7 +196,7 @@ module.exports = { | 185 | 196 | { | 186 | 197 | files: [ | 187 | 198 | 'scripts/eslint-rules/*.js', | 188 | | - 'packages/eslint-plugin-react-hooks/src/*.js' | | 199 | + 'packages/eslint-plugin-react-hooks/src/*.js', | 189 | 200 | ], | 190 | 201 | plugins: ['eslint-plugin'], | 191 | 202 | rules: { | |
Collapse file Copy file name to clipboardExpand all lines: dangerfile.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -102,8 +102,8 @@ function row(result) { | 102 | 102 | let headSha; | 103 | 103 | let baseSha; | 104 | 104 | try { | 105 | | - headSha = (readFileSync(HEAD_DIR + '/COMMIT_SHA') + '').trim(); | 106 | | - baseSha = (readFileSync(BASE_DIR + '/COMMIT_SHA') + '').trim(); | | 105 | + headSha = String(readFileSync(HEAD_DIR + '/COMMIT_SHA')).trim(); | | 106 | + baseSha = String(readFileSync(BASE_DIR + '/COMMIT_SHA')).trim(); | 107 | 107 | } catch { | 108 | 108 | warn( | 109 | 109 | "Failed to read build artifacts. It's possible a build configuration " + | |
Collapse file Copy file name to clipboardExpand all lines: fixtures/dom/src/components/fixtures/error-handling/index.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,7 @@ class ErrorBoundary extends React.Component { | 41 | 41 | if (this.state.error) { | 42 | 42 | return <p>Captured an error: {this.state.error.message}</p>; | 43 | 43 | } else { | 44 | | - return <p>Captured an error: {'' + this.state.error}</p>; | | 44 | + return <p>Captured an error: {String(this.state.error)}</p>; | 45 | 45 | } | 46 | 46 | } | 47 | 47 | if (this.state.shouldThrow) { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -615,7 +615,7 @@ describe('ReactHooksInspectionIntegration', () => { | 615 | 615 | expect(tree[0].id).toEqual(0); | 616 | 616 | expect(tree[0].isStateEditable).toEqual(false); | 617 | 617 | expect(tree[0].name).toEqual('OpaqueIdentifier'); | 618 | | - expect((tree[0].value + '').startsWith('c_')).toBe(true); | | 618 | + expect(String(tree[0].value).startsWith('c_')).toBe(true); | 619 | 619 |
| 620 | 620 | expect(tree[1]).toEqual({ | 621 | 621 | id: 1, | @@ -646,7 +646,7 @@ describe('ReactHooksInspectionIntegration', () => { | 646 | 646 | expect(tree[0].id).toEqual(0); | 647 | 647 | expect(tree[0].isStateEditable).toEqual(false); | 648 | 648 | expect(tree[0].name).toEqual('OpaqueIdentifier'); | 649 | | - expect((tree[0].value + '').startsWith('c_')).toBe(true); | | 649 | + expect(String(tree[0].value).startsWith('c_')).toBe(true); | 650 | 650 |
| 651 | 651 | expect(tree[1]).toEqual({ | 652 | 652 | id: 1, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-extensions/src/main.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -94,7 +94,7 @@ function createPanelIfReactLoaded() { | 94 | 94 |
| 95 | 95 | function initBridgeAndStore() { | 96 | 96 | const port = chrome.runtime.connect({ | 97 | | - name: '' + tabId, | | 97 | + name: String(tabId), | 98 | 98 | }); | 99 | 99 | // Looks like `port.onDisconnect` does not trigger on in-tab navigation like new URL or back/forward navigation, | 100 | 100 | // so it makes no sense to handle it here. | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/legacy/renderer.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -63,7 +63,7 @@ function getData(internalInstance: InternalInstance) { | 63 | 63 | // != used deliberately here to catch undefined and null | 64 | 64 | if (internalInstance._currentElement != null) { | 65 | 65 | if (internalInstance._currentElement.key) { | 66 | | - key = '' + internalInstance._currentElement.key; | | 66 | + key = String(internalInstance._currentElement.key); | 67 | 67 | } | 68 | 68 |
| 69 | 69 | const elementType = internalInstance._currentElement.type; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/renderer.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1848,7 +1848,7 @@ export function attach( | 1848 | 1848 |
| 1849 | 1849 | // This check is a guard to handle a React element that has been modified | 1850 | 1850 | // in such a way as to bypass the default stringification of the "key" property. | 1851 | | - const keyString = key === null ? null : '' + key; | | 1851 | + const keyString = key === null ? null : String(key); | 1852 | 1852 | const keyStringID = getStringID(keyString); | 1853 | 1853 |
| 1854 | 1854 | pushOperation(TREE_OPERATION_ADD); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/backend/utils.js +3-10Lines changed: 3 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -166,11 +166,7 @@ export function format( | 166 | 166 | ): string { | 167 | 167 | const args = inputArgs.slice(); | 168 | 168 |
| 169 | | - // Symbols cannot be concatenated with Strings. | 170 | | - let formatted: string = | 171 | | - typeof maybeMessage === 'symbol' | 172 | | - ? maybeMessage.toString() | 173 | | - : '' + maybeMessage; | | 169 | + let formatted: string = String(maybeMessage); | 174 | 170 |
| 175 | 171 | // If the first argument is a string, check for substitutions. | 176 | 172 | if (typeof maybeMessage === 'string') { | @@ -203,17 +199,14 @@ export function format( | 203 | 199 | // Arguments that remain after formatting. | 204 | 200 | if (args.length) { | 205 | 201 | for (let i = 0; i < args.length; i++) { | 206 | | - const arg = args[i]; | 207 | | - | 208 | | - // Symbols cannot be concatenated with Strings. | 209 | | - formatted += ' ' + (typeof arg === 'symbol' ? arg.toString() : arg); | | 202 | + formatted += ' ' + String(args[i]); | 210 | 203 | } | 211 | 204 | } | 212 | 205 |
| 213 | 206 | // Update escaped %% values. | 214 | 207 | formatted = formatted.replace(/%{2,2}/g, '%'); | 215 | 208 |
| 216 | | - return '' + formatted; | | 209 | + return String(formatted); | 217 | 210 | } | 218 | 211 |
| 219 | 212 | export function isSynchronousXHRSupported(): boolean { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/devtools/views/ErrorBoundary/ErrorBoundary.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -46,7 +46,7 @@ export default class ErrorBoundary extends Component<Props, State> { | 46 | 46 | error !== null && | 47 | 47 | error.hasOwnProperty('message') | 48 | 48 | ? error.message | 49 | | - : '' + error; | | 49 | + : String(error); | 50 | 50 |
| 51 | 51 | const callStack = | 52 | 52 | typeof error === 'object' && | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-devtools-shared/src/devtools/views/utils.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,8 +19,8 @@ export function alphaSortEntries( | 19 | 19 | ): number { | 20 | 20 | const a = entryA[0]; | 21 | 21 | const b = entryB[0]; | 22 | | - if ('' + +a === a) { | 23 | | - if ('' + +b !== b) { | | 22 | + if (String(+a) === a) { | | 23 | + if (String(+b) !== b) { | 24 | 24 | return -1; | 25 | 25 | } | 26 | 26 | return +a < +b ? -1 : 1; | |
|