-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
fix(devtools): check if data for commit index exists #18345
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 466d0ed:
|
@bvaughn Do check these when you get time and lmk if the PR makes sense. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jyash97 Nice repro! Can you share the source for the repro app?
if ( | ||
operations != null && | ||
commitIndex < operations.length && | ||
operations[commitIndex] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should find and fix the underlying cause here. Why is operations[commitIndex]
undefined
? That's unexpected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On debugging the underlying issue, I encountered this issue so I thought it would be better to add the check and get the correct error.
Hey @bvaughn thanks for taking a look. |
There is a duplicate key warning in this app:
I don't understand why it manifests the way it does with the Profiler, but if you fix that warning- the behavior of your app is what I would expect (and the Profiler works fine). (See here.) |
I've reduced the error case to poke around a little further though, to see if I can figure out why the Profiler is reacting the way it is. (See here.) const One = () => null;
const Two = () => null;
function App() {
const [didMount, setDidMount] = useState(false);
useEffect(() => {
setDidMount(true);
}, []);
return (
<>
{didMount ? <Two /> : <One key={1} />}
<One key={1} />
</>
);
} |
Ah, I see why the Profiler is erroring in this case. The invalid react/packages/react-devtools-shared/src/devtools/store.js Lines 929 to 933 in 0140118
This thrown error means that the Profiler code that normally processes the commit (after the Components store) doesn't run. I may update this specifically, but in general- this case isn't really meant to be supported. I wish we "failed" in a more meaningful way though! Let me give it a little thought. |
I've opened an alternate "fix" for this: #18378 Want to check it out? |
Hey @bvaughn thanks for the review and letting me know the underneath issue. I will surely take look at your PR 💯 |
Summary
After Reload and profiling this app: https://gsqzl.csb.app/, traverse through the commit. Devtools break and throw an error for accessing data from
undefined
ornull
.Profiling Data: https://gist.github.com/jyash97/612bc8d38c2f7f9842c19ae5d270252c
For more ref: #18033 (comment)
Test Plan
Added the check if the commit data exists than only access the value.
Tested with firefox, chrome extension and with inline package.
Commands used
&
Screenshot Recording of Chrome extension: https://youtu.be/1UyEZcfbjqg