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

devtools: Display root type for root updates in "what caused this update?" #22599

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Object {
"timestamp": 16,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -91,7 +91,7 @@ Object {
"timestamp": 15,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -127,7 +127,7 @@ Object {
"timestamp": 18,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -190,7 +190,7 @@ Object {
"timestamp": 12,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -258,7 +258,7 @@ Object {
"timestamp": 25,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -307,7 +307,7 @@ Object {
"timestamp": 35,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -346,7 +346,7 @@ Object {
"timestamp": 45,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -455,7 +455,7 @@ Object {
"timestamp": 12,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -562,7 +562,7 @@ Object {
"timestamp": 25,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -632,7 +632,7 @@ Object {
"timestamp": 35,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -683,7 +683,7 @@ Object {
"timestamp": 45,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -954,7 +954,7 @@ Object {
"timestamp": 11,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -1042,7 +1042,7 @@ Object {
"timestamp": 22,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -1149,7 +1149,7 @@ Object {
"timestamp": 35,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -1359,7 +1359,7 @@ Object {
"timestamp": 13,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -1405,7 +1405,7 @@ Object {
"timestamp": 34,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -1441,7 +1441,7 @@ Object {
"timestamp": 44,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -1624,7 +1624,7 @@ Object {
"timestamp": 24,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 13,
"key": null,
Expand Down Expand Up @@ -1714,7 +1714,7 @@ Object {
"timestamp": 34,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 7,
"key": null,
Expand Down Expand Up @@ -1892,7 +1892,7 @@ Object {
"timestamp": 13,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -1962,7 +1962,7 @@ Object {
"timestamp": 34,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2013,7 +2013,7 @@ Object {
"timestamp": 44,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2256,7 +2256,7 @@ Object {
"timestamp": 24,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 13,
"key": null,
Expand Down Expand Up @@ -2343,7 +2343,7 @@ Object {
"timestamp": 34,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 7,
"key": null,
Expand Down Expand Up @@ -2464,7 +2464,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2541,7 +2541,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2584,7 +2584,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2699,7 +2699,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2740,7 +2740,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2811,7 +2811,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -2878,7 +2878,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -3029,7 +3029,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -3094,7 +3094,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -3271,7 +3271,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -3441,7 +3441,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -3523,7 +3523,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -3604,7 +3604,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -3739,7 +3739,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -4011,7 +4011,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -4147,7 +4147,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down Expand Up @@ -4282,7 +4282,7 @@ Object {
"timestamp": 0,
"updaters": Array [
Object {
"displayName": "Anonymous",
"displayName": "render()",
"hocDisplayNames": null,
"id": 1,
"key": null,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ export function getInternalReactConstants(
getDisplayName(resolvedType, 'Anonymous')
);
case HostRoot:
const fiberRoot = fiber.stateNode;
if (fiberRoot != null && fiberRoot._debugRootType !== null) {
return fiberRoot._debugRootType;
}
Comment on lines +428 to +431
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a bit misleading for the new roots since it's not actaully the createRoot() call but createRoot().render().

Could also do return `render(${getDisplayNameForRoot(fiber)})`; but that's misleading for legacy ReactDOM.hydrate().

Open to suggestions here. Mainly opening this to draw attention to the fact that updates to roots are displayed as "anonymous"

return null;
case HostComponent:
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as React from 'react';
import {useContext} from 'react';
import {ProfilerContext} from './ProfilerContext';
import styles from './Updaters.css';
import {ElementTypeRoot} from '../../../types';

export type Props = {|
commitTree: CommitTree,
Expand All @@ -26,8 +27,9 @@ export default function Updaters({commitTree, updaters}: Props) {
const children =
updaters.length > 0 ? (
updaters.map<React$Node>((serializedElement: SerializedElement) => {
const {displayName, id, key} = serializedElement;
const isVisibleInTree = commitTree.nodes.has(id);
const {displayName, id, key, type} = serializedElement;
const isVisibleInTree =
commitTree.nodes.has(id) && type !== ElementTypeRoot;
Comment on lines +31 to +32
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit sketchy. Ideally we had some unified notion of what's visible in the tree instead of each component checking that logic. But maybe this is fine for now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably okay for now.

if (isVisibleInTree) {
return (
<button
Expand Down