react: [DevTools Bug] Could not inspect element with id "1335"
Website or app
Web app we are developing for a client.
Repro steps
Open the components tab - no components will display Close the components tab Open the components tab again, this time the the components show but the error shows on the right pane.
How often does this bug happen?
Often
DevTools package (automated)
react-devtools-extensions
DevTools version (automated)
4.14.0-d0ec283819
Error message (automated)
Could not inspect element with id “1335”
Error call stack (automated)
No response
Error component stack (automated)
InspectedElementContextController@testErrorStack.js:109842:43
Suspense
ErrorBoundary_ErrorBoundary@testErrorStack.js:108452:5
div
InspectedElementErrorBoundaryWrapper@testErrorStack.js:108838:46
NativeStyleContextController@testErrorStack.js:111206:38
div
div
OwnersListContextController@testErrorStack.js:106680:37
SettingsModalContextController@testErrorStack.js:107121:40
Components_Components@testErrorStack.js:113123:52
ErrorBoundary_ErrorBoundary@testErrorStack.js:108452:5
PortaledContent@testErrorStack.js:108571:34
div
div
ProfilerContextController@testErrorStack.js:112748:35
TreeContextController@testErrorStack.js:103336:31
SettingsContextController@testErrorStack.js:103939:35
ModalDialogContextController@testErrorStack.js:108901:38
DevTools_DevTools@testErrorStack.js:115897:27
GitHub query string (automated)
https://api.github.com/search/issues?q=Could not inspect element with id in:title is:issue is:open is:public label:"Component: Developer Tools" repo:facebook/react
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 15 (9 by maintainers)
Thank you for the repro, @HonbraDev! 🙇🏼
Interestingly, this did not reproduce the error for me when I first tried it. Then I went to record a video showing that it worked and the second time, it did reproduce for me.
Enabling
__DEBUG__logging shows the following high level sequence:When the page loads initially (host component filter enabled):
When component filters are changed, first the old root is dropped:
Then re-added with new (unfiltered) tree:
The interesting part is this:
The root element (“b”) is being added from the backend with an id of
2in both cases, but when the frontend tries to inspect the element with id2an error is thrown.I think this is actually happening because of an optimization in how the frontend “inspects” an element. When the element is first selected, the backend inspects the props and state. After, the frontend periodically asks the backend to re-inspect. If the element hasn’t rendered since it was last inspected, the backend tells the frontend there has been no change. The frontend then returns the same, previously inspected value: https://github.com/facebook/react/blob/bd5bf555e1167e7088a4391e5cd419dccb39714c/packages/react-devtools-shared/src/inspectedElementMutableSource.js#L67-L72
In this case though, the
inspectedElementMaphas no entry for theElementwith id2because the filter change dropped and recreated all of the elements.I think the most straight forward way to fix this is to maybe have the backend generate new ids when a root is dropped like this. Need to think it over some and try to catch this case in a unit test first.
Edit 1: I think clearing the Fiber-to-id map on the backend when component filters change not be great either because it would cause us to lose any error/warning data associated with a fiber. I think a more narrowly focused fix would be to update this code: https://github.com/facebook/react/blob/bd5bf555e1167e7088a4391e5cd419dccb39714c/packages/react-devtools-shared/src/backend/renderer.js#L804-L807
To reset
mostRecentlyInspectedElement:I believe #22160 fixes this.
Planning a release today.