Skip to content

Commit ea5c55a

Browse files
committed
Current behavior for rootType
1 parent 8209de2 commit ea5c55a

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

packages/react-devtools-shared/src/__tests__/inspectedElement-test.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ describe('InspectedElement', () => {
176176
"a": 1,
177177
"b": "abc",
178178
},
179+
"rootType": "createLegacyRoot()",
179180
"state": null,
180181
}
181182
`);
@@ -1584,6 +1585,7 @@ describe('InspectedElement', () => {
15841585
"a": 1,
15851586
"b": "abc",
15861587
},
1588+
"rootType": "createLegacyRoot()",
15871589
"state": null,
15881590
}
15891591
`);
@@ -1912,6 +1914,7 @@ describe('InspectedElement', () => {
19121914
"id": 2,
19131915
"owners": null,
19141916
"props": Object {},
1917+
"rootType": "createLegacyRoot()",
19151918
"state": null,
19161919
}
19171920
`);
@@ -1944,11 +1947,71 @@ describe('InspectedElement', () => {
19441947
"id": 2,
19451948
"owners": null,
19461949
"props": Object {},
1950+
"rootType": "createLegacyRoot()",
19471951
"state": null,
19481952
}
19491953
`);
19501954
});
19511955

1956+
it('should display the root type for ReactDOM.hydrate', async () => {
1957+
const Example = () => <div />;
1958+
1959+
await utils.actAsync(() => {
1960+
const container = document.createElement('div');
1961+
container.innerHTML = '<div></div>';
1962+
withErrorsOrWarningsIgnored(
1963+
['ReactDOM.hydrate is no longer supported in React 18'],
1964+
() => {
1965+
ReactDOM.hydrate(<Example />, container);
1966+
},
1967+
);
1968+
}, false);
1969+
1970+
const inspectedElement = await inspectElementAtIndex(0);
1971+
expect(inspectedElement.rootType).toMatchInlineSnapshot(
1972+
`"createLegacyRoot()"`,
1973+
);
1974+
});
1975+
1976+
it('should display the root type for ReactDOM.render', async () => {
1977+
const Example = () => <div />;
1978+
1979+
await utils.actAsync(() => {
1980+
const container = document.createElement('div');
1981+
legacyRender(<Example />, container);
1982+
}, false);
1983+
1984+
const inspectedElement = await inspectElementAtIndex(0);
1985+
expect(inspectedElement.rootType).toMatchInlineSnapshot(
1986+
`"createLegacyRoot()"`,
1987+
);
1988+
});
1989+
1990+
it('should display the root type for ReactDOM.hydrateRoot', async () => {
1991+
const Example = () => <div />;
1992+
1993+
await utils.actAsync(() => {
1994+
const container = document.createElement('div');
1995+
container.innerHTML = '<div></div>';
1996+
ReactDOM.hydrateRoot(container).render(<Example />);
1997+
}, false);
1998+
1999+
const inspectedElement = await inspectElementAtIndex(0);
2000+
expect(inspectedElement.rootType).toMatchInlineSnapshot(`"createRoot()"`);
2001+
});
2002+
2003+
it('should display the root type for ReactDOM.createRoot', async () => {
2004+
const Example = () => <div />;
2005+
2006+
await utils.actAsync(() => {
2007+
const container = document.createElement('div');
2008+
ReactDOM.createRoot(container).render(<Example />);
2009+
}, false);
2010+
2011+
const inspectedElement = await inspectElementAtIndex(0);
2012+
expect(inspectedElement.rootType).toMatchInlineSnapshot(`"createRoot()"`);
2013+
});
2014+
19522015
describe('$r', () => {
19532016
it('should support function components', async () => {
19542017
const Example = () => {

packages/react-devtools-shared/src/__tests__/inspectedElementSerializer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function print(inspectedElement, serialize, indent) {
3030
id: inspectedElement.id,
3131
owners: inspectedElement.owners,
3232
props: inspectedElement.props,
33+
rootType: inspectedElement.rootType,
3334
state: inspectedElement.state,
3435
});
3536
}

packages/react-devtools-shared/src/__tests__/legacy/inspectElement-test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ describe('InspectedElementContext', () => {
8383
"a": 1,
8484
"b": "abc",
8585
},
86+
"rootType": null,
8687
"state": null,
8788
}
8889
`);
@@ -133,6 +134,7 @@ describe('InspectedElementContext', () => {
133134
"value_null": null,
134135
"value_undefined": undefined,
135136
},
137+
"rootType": null,
136138
"state": null,
137139
}
138140
`);
@@ -408,6 +410,7 @@ describe('InspectedElementContext', () => {
408410
"preview_long": Generator,
409411
},
410412
},
413+
"rootType": null,
411414
"state": null,
412415
}
413416
`);
@@ -461,6 +464,7 @@ describe('InspectedElementContext', () => {
461464
"number": 42,
462465
},
463466
},
467+
"rootType": null,
464468
"state": null,
465469
}
466470
`);
@@ -552,6 +556,7 @@ describe('InspectedElementContext', () => {
552556
"enumerableStringBase": 1,
553557
},
554558
},
559+
"rootType": null,
555560
"state": null,
556561
}
557562
`);

0 commit comments

Comments
 (0)