Skip to content
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
18 changes: 9 additions & 9 deletions packages/react-client/src/__tests__/ReactFlight-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2822,7 +2822,7 @@ describe('ReactFlight', () => {
expect(getDebugInfo(promise)).toEqual(
__DEV__
? [
{time: 20},
{time: gate(flags => flags.enableAsyncDebugInfo) ? 22 : 20},
{
name: 'ServerComponent',
env: 'Server',
Expand All @@ -2832,7 +2832,7 @@ describe('ReactFlight', () => {
transport: expect.arrayContaining([]),
},
},
{time: 21},
{time: gate(flags => flags.enableAsyncDebugInfo) ? 23 : 21},
]
: undefined,
);
Expand All @@ -2843,46 +2843,46 @@ describe('ReactFlight', () => {
expect(getDebugInfo(thirdPartyChildren[0])).toEqual(
__DEV__
? [
{time: 22}, // Clamped to the start
{time: gate(flags => flags.enableAsyncDebugInfo) ? 24 : 22}, // Clamped to the start
{
name: 'ThirdPartyComponent',
env: 'third-party',
key: null,
stack: ' in Object.<anonymous> (at **)',
props: {},
},
{time: 22},
{time: 23}, // This last one is when the promise resolved into the first party.
{time: gate(flags => flags.enableAsyncDebugInfo) ? 24 : 22},
{time: gate(flags => flags.enableAsyncDebugInfo) ? 25 : 23}, // This last one is when the promise resolved into the first party.
]
: undefined,
);
expect(getDebugInfo(thirdPartyChildren[1])).toEqual(
__DEV__
? [
{time: 22}, // Clamped to the start
{time: gate(flags => flags.enableAsyncDebugInfo) ? 24 : 22}, // Clamped to the start
{
name: 'ThirdPartyLazyComponent',
env: 'third-party',
key: null,
stack: ' in myLazy (at **)\n in lazyInitializer (at **)',
props: {},
},
{time: 22},
{time: gate(flags => flags.enableAsyncDebugInfo) ? 24 : 22},
]
: undefined,
);
expect(getDebugInfo(thirdPartyChildren[2])).toEqual(
__DEV__
? [
{time: 22},
{time: gate(flags => flags.enableAsyncDebugInfo) ? 24 : 22},
{
name: 'ThirdPartyFragmentComponent',
env: 'third-party',
key: '3',
stack: ' in Object.<anonymous> (at **)',
props: {},
},
{time: 22},
{time: gate(flags => flags.enableAsyncDebugInfo) ? 24 : 22},
]
: undefined,
);
Expand Down
22 changes: 21 additions & 1 deletion packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
let currentFiber: null | Fiber = null;
let currentHook: null | Hook = null;
let currentContextDependency: null | ContextDependency<mixed> = null;
let currentThenableIndex: number = 0;
let currentThenableState: null | Array<Thenable<mixed>> = null;

function nextHook(): null | Hook {
const hook = currentHook;
Expand Down Expand Up @@ -201,7 +203,15 @@ function use<T>(usable: Usable<T>): T {
if (usable !== null && typeof usable === 'object') {
// $FlowFixMe[method-unbinding]
if (typeof usable.then === 'function') {
const thenable: Thenable<any> = (usable: any);
const thenable: Thenable<any> =
// If we have thenable state, then the actually used thenable will be the one
// stashed in it. It's possible for uncached Promises to be new each render
// and in that case the one we're inspecting is the in the thenable state.
currentThenableState !== null &&
currentThenableIndex < currentThenableState.length
? currentThenableState[currentThenableIndex++]
: (usable: any);

switch (thenable.status) {
case 'fulfilled': {
const fulfilledValue: T = thenable.value;
Expand Down Expand Up @@ -1285,6 +1295,14 @@ export function inspectHooksOfFiber(
// current state from them.
currentHook = (fiber.memoizedState: Hook);
currentFiber = fiber;
const thenableState =
fiber.dependencies && fiber.dependencies._debugThenableState;
// In DEV the thenableState is an inner object.
const usedThenables: any = thenableState
? thenableState.thenables || thenableState
: null;
currentThenableState = Array.isArray(usedThenables) ? usedThenables : null;
currentThenableIndex = 0;

if (hasOwnProperty.call(currentFiber, 'dependencies')) {
// $FlowFixMe[incompatible-use]: Flow thinks hasOwnProperty might have nulled `currentFiber`
Expand Down Expand Up @@ -1339,6 +1357,8 @@ export function inspectHooksOfFiber(
currentFiber = null;
currentHook = null;
currentContextDependency = null;
currentThenableState = null;
currentThenableIndex = 0;

restoreContexts(contextMap);
}
Expand Down
15 changes: 13 additions & 2 deletions packages/react-devtools-inline/__tests__/__e2e__/devtools-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,22 @@ async function selectElement(
createTestNameSelector('InspectedElementView-Owners'),
])[0];

if (!ownersList) {
return false;
}

const owners = findAllNodes(ownersList, [
createTestNameSelector('OwnerView'),
]);

return (
title &&
title.innerText.includes(titleText) &&
ownersList &&
ownersList.innerText.includes(ownersListText)
owners &&
owners
.map(node => node.innerText)
.join('\n')
.includes(ownersListText)
);
},
{titleText: displayName, ownersListText: waitForOwnersText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ describe('InspectedElement', () => {
object_with_symbol={objectWithSymbol}
proxy={proxyInstance}
react_element={<span />}
react_lazy={React.lazy(async () => ({default: 'foo'}))}
regexp={/abc/giu}
set={setShallow}
set_of_sets={setOfSets}
Expand Down Expand Up @@ -780,9 +781,18 @@ describe('InspectedElement', () => {
"preview_short": () => {},
"preview_long": () => {},
},
"react_element": Dehydrated {
"preview_short": <span />,
"preview_long": <span />,
"react_element": {
"key": null,
"props": Dehydrated {
"preview_short": {…},
"preview_long": {},
},
},
"react_lazy": {
"_payload": Dehydrated {
"preview_short": {…},
"preview_long": {_ioInfo: {…}, _result: () => {}, _status: -1},
},
},
"regexp": Dehydrated {
"preview_short": /abc/giu,
Expand Down Expand Up @@ -930,13 +940,13 @@ describe('InspectedElement', () => {
const inspectedElement = await inspectElementAtIndex(0);

expect(inspectedElement.props).toMatchInlineSnapshot(`
{
"unusedPromise": Dehydrated {
"preview_short": Promise,
"preview_long": Promise,
},
}
`);
{
"unusedPromise": Dehydrated {
"preview_short": Promise,
"preview_long": Promise,
},
}
`);
});

it('should not consume iterables while inspecting', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,13 @@ describe('InspectedElementContext', () => {
"preview_long": {boolean: true, number: 123, string: "abc"},
},
},
"react_element": Dehydrated {
"preview_short": <span />,
"preview_long": <span />,
"react_element": {
"key": null,
"props": Dehydrated {
"preview_short": {…},
"preview_long": {},
},
"ref": null,
},
"regexp": Dehydrated {
"preview_short": /abc/giu,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ describe('ProfilingCache', () => {
"hocDisplayNames": null,
"id": 1,
"key": null,
"stack": null,
"type": 11,
},
],
Expand Down
Loading
Loading