fix: useLinking crash#10262
Conversation
|
Hey roryabraham! Thanks for opening your first pull request in this repo. If you haven't already, make sure to read our contribution guidelines. |
|
✔️ Deploy Preview for react-navigation-example ready! 🔨 Explore the source changes: 66eca91 🔍 Inspect the deploy log: https://app.netlify.com/sites/react-navigation-example/deploys/61e5f8d2525f4a000743cc37 😎 Browse the preview: https://deploy-preview-10262--react-navigation-example.netlify.app/ |
Codecov Report
@@ Coverage Diff @@
## main #10262 +/- ##
=======================================
Coverage 74.41% 74.41%
=======================================
Files 160 160
Lines 4858 4855 -3
Branches 1838 1836 -2
=======================================
- Hits 3615 3613 -2
+ Misses 1209 1208 -1
Partials 34 34
Continue to review full report at Codecov.
|
|
Yihaaa! |
|
Thank you for the PR and investigation |
|
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
Hello 👋 We've been seeing [this crash](react-navigation#9970 (comment)) (shown in the following screenshot) happening in our production code. I unfortunately don't know how to consistently reproduce this problem, but I believe this PR is very safe and will fix the issue.  As explained in [this comment](https://github.com/react-navigation/react-navigation/pull/9970/files#r784475821), `TypeError: Cannot read property 'id' of undefined` tells us that somehow the `items` array is actually getting in a state where it contains `undefined`. Now, there's only four places the `items` array is written to: [line 84](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L84), [line 86](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L86), [line 108](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L108), and [line 110](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L110). Reviewing these one-by-one: #### Line 84 `items = items.slice(0, index - 1)` -> I don't see any way this can add an `undefined` value to the array ❌ #### Line 86 `items.push({ path, state, id })` -> At worst, this could append an object like: `{path: undefined, state: undefined, id: undefined}`, but we wouldn't end up with `undefined` itself in the `items` array. So not here either ❌ #### Line 108 `items = [{ path, state, id }];` -> Similar to line 86, this can't cause `undefined` to be in the `items` array ❌ #### Line 110 `items[index] = { path, state, id };` -> This _can_ cause `undefined` to be in the `items` array if `index` is greater than the length of the array, like so: ```js > let items = []; undefined > items[1] = 'Hello'; 'Hello' > items[0]; undefined ``` It seems this is our problem line, and tells us that the `index` is becoming greater than the length of the items array. I believe I found the only location in this component where that could happen, and fix it in this PR. Let me know if you have questions or concerns! If anyone from the community wants to help out with providing testing or consistent reproduction steps, that would be great!
Hello 👋 We've been seeing [this crash](react-navigation#9970 (comment)) (shown in the following screenshot) happening in our production code. I unfortunately don't know how to consistently reproduce this problem, but I believe this PR is very safe and will fix the issue.  As explained in [this comment](https://github.com/react-navigation/react-navigation/pull/9970/files#r784475821), `TypeError: Cannot read property 'id' of undefined` tells us that somehow the `items` array is actually getting in a state where it contains `undefined`. Now, there's only four places the `items` array is written to: [line 84](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L84), [line 86](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L86), [line 108](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L108), and [line 110](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L110). Reviewing these one-by-one: #### Line 84 `items = items.slice(0, index - 1)` -> I don't see any way this can add an `undefined` value to the array ❌ #### Line 86 `items.push({ path, state, id })` -> At worst, this could append an object like: `{path: undefined, state: undefined, id: undefined}`, but we wouldn't end up with `undefined` itself in the `items` array. So not here either ❌ #### Line 108 `items = [{ path, state, id }];` -> Similar to line 86, this can't cause `undefined` to be in the `items` array ❌ #### Line 110 `items[index] = { path, state, id };` -> This _can_ cause `undefined` to be in the `items` array if `index` is greater than the length of the array, like so: ```js > let items = []; undefined > items[1] = 'Hello'; 'Hello' > items[0]; undefined ``` It seems this is our problem line, and tells us that the `index` is becoming greater than the length of the items array. I believe I found the only location in this component where that could happen, and fix it in this PR. Let me know if you have questions or concerns! If anyone from the community wants to help out with providing testing or consistent reproduction steps, that would be great!
Hello 👋 We've been seeing [this crash](react-navigation#9970 (comment)) (shown in the following screenshot) happening in our production code. I unfortunately don't know how to consistently reproduce this problem, but I believe this PR is very safe and will fix the issue.  As explained in [this comment](https://github.com/react-navigation/react-navigation/pull/9970/files#r784475821), `TypeError: Cannot read property 'id' of undefined` tells us that somehow the `items` array is actually getting in a state where it contains `undefined`. Now, there's only four places the `items` array is written to: [line 84](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L84), [line 86](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L86), [line 108](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L108), and [line 110](https://github.com/react-navigation/react-navigation/blob/fb84805c889bbb7059e7e95592c004aea2a510d6/packages/native/src/useLinking.tsx#L110). Reviewing these one-by-one: #### Line 84 `items = items.slice(0, index - 1)` -> I don't see any way this can add an `undefined` value to the array ❌ #### Line 86 `items.push({ path, state, id })` -> At worst, this could append an object like: `{path: undefined, state: undefined, id: undefined}`, but we wouldn't end up with `undefined` itself in the `items` array. So not here either ❌ #### Line 108 `items = [{ path, state, id }];` -> Similar to line 86, this can't cause `undefined` to be in the `items` array ❌ #### Line 110 `items[index] = { path, state, id };` -> This _can_ cause `undefined` to be in the `items` array if `index` is greater than the length of the array, like so: ```js > let items = []; undefined > items[1] = 'Hello'; 'Hello' > items[0]; undefined ``` It seems this is our problem line, and tells us that the `index` is becoming greater than the length of the items array. I believe I found the only location in this component where that could happen, and fix it in this PR. Let me know if you have questions or concerns! If anyone from the community wants to help out with providing testing or consistent reproduction steps, that would be great!
|
Hey @chrda81! I'm also running into this error intermittently & planning to debug, but unable to reproduce. Could you tell the step by step to repro for the drawer (unsure, is this also intermittent for drawer)? A video would be great! Thank you 😄 Another note: this seems to happen a lot in Chrome (unsure if this is related) |

Hello 👋
We've been seeing this crash (shown in the following screenshot) happening in our production code. I unfortunately don't know how to consistently reproduce this problem, but I believe this PR is very safe and will fix the issue.
As explained in this comment,
TypeError: Cannot read property 'id' of undefinedtells us that somehow theitemsarray is actually getting in a state where it containsundefined.Now, there's only four places the
itemsarray is written to: line 84, line 86, line 108, and line 110.Reviewing these one-by-one:
Line 84
items = items.slice(0, index - 1)-> I don't see any way this can add anundefinedvalue to the array ❌Line 86
items.push({ path, state, id })-> At worst, this could append an object like:{path: undefined, state: undefined, id: undefined}, but we wouldn't end up withundefineditself in theitemsarray. So not here either ❌Line 108
items = [{ path, state, id }];-> Similar to line 86, this can't causeundefinedto be in theitemsarray ❌Line 110
items[index] = { path, state, id };-> This can causeundefinedto be in theitemsarray ifindexis greater than the length of the array, like so:It seems this is our problem line, and tells us that the
indexis becoming greater than the length of the items array. I believe I found the only location in this component where that could happen, and fix it in this PR.Let me know if you have questions or concerns! If anyone from the community wants to help out with providing testing or consistent reproduction steps, that would be great!