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
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,11 @@ exports[`Store should show the right display names for special component types 1
<MyComponent>
<MyComponent> [ForwardRef]
▾ <Anonymous> [ForwardRef]
<MyComponent>
<MyComponent2>
<Custom> [ForwardRef]
<MyComponent> [Memo]
<MyComponent4> [Memo]
▾ <MyComponent> [Memo]
<MyComponent> [ForwardRef]
▾ <Suspense>
<MyComponent>
<MyComponent5>
`;
12 changes: 8 additions & 4 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,16 +856,20 @@ describe('Store', () => {

const MyComponent = (props, ref) => null;
const FowardRefComponent = React.forwardRef(MyComponent);
const MyComponent2 = (props, ref) => null;
const FowardRefComponentWithAnonymousFunction = React.forwardRef(() => (
<MyComponent />
<MyComponent2 />
));
const MyComponent3 = (props, ref) => null;
const FowardRefComponentWithCustomDisplayName = React.forwardRef(
MyComponent,
MyComponent3,
);
FowardRefComponentWithCustomDisplayName.displayName = 'Custom';
const MemoComponent = React.memo(MyComponent);
const MyComponent4 = (props, ref) => null;
const MemoComponent = React.memo(MyComponent4);
const MemoForwardRefComponent = React.memo(FowardRefComponent);
const LazyComponent = React.lazy(() => fakeImport(MyComponent));
const MyComponent5 = (props, ref) => null;
const LazyComponent = React.lazy(() => fakeImport(MyComponent5));

const App = () => (
<React.Fragment>
Expand Down
4 changes: 1 addition & 3 deletions packages/react-dom/src/__tests__/findDOMNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ describe('findDOMNode', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in div (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child);
Expand Down Expand Up @@ -154,8 +153,7 @@ describe('findDOMNode', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in div (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)',
'\n in IsInStrictMode (at **)',
]);
expect(match).toBe(child);
});
Expand Down
12 changes: 6 additions & 6 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {ReactProvider, ReactContext} from 'shared/ReactTypes';
import * as React from 'react';
import invariant from 'shared/invariant';
import getComponentName from 'shared/getComponentName';
import describeComponentFrame from 'shared/describeComponentFrame';
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {
warnAboutDeprecatedLifecycles,
Expand Down Expand Up @@ -112,11 +112,11 @@ if (__DEV__) {
};

describeStackFrame = function(element): string {
const source = element._source;
const type = element.type;
const name = getComponentName(type);
const ownerName = null;
return describeComponentFrame(name, source, ownerName);
return describeUnknownElementTypeFrameInDEV(
element.type,
element._source,
null,
);
};

pushCurrentDebugStack = function(stack: Array<Frame>) {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-renderer/src/ReactNativeRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
getPublicRootInstance,
} from 'react-reconciler/src/ReactFiberReconciler';
// TODO: direct imports like some-package/src/* are bad. Fix me.
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactCurrentFiber';
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactFiberComponentStack';
import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
import {
setBatchingImplementation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ describe('ReactFabric', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child);
Expand Down Expand Up @@ -811,8 +810,7 @@ describe('ReactFabric', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)',
'\n in IsInStrictMode (at **)',
]);
expect(match).toBe(child);
});
Expand Down Expand Up @@ -846,7 +844,6 @@ describe('ReactFabric', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child._nativeTag);
Expand Down Expand Up @@ -882,8 +879,7 @@ describe('ReactFabric', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)',
'\n in IsInStrictMode (at **)',
]);
expect(match).toBe(child._nativeTag);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ describe('ReactNative', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child);
Expand Down Expand Up @@ -521,8 +520,7 @@ describe('ReactNative', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)',
'\n in IsInStrictMode (at **)',
]);
expect(match).toBe(child);
});
Expand Down Expand Up @@ -556,7 +554,6 @@ describe('ReactNative', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in StrictMode (at **)' +
'\n in ContainsStrictModeChild (at **)',
]);
expect(match).toBe(child._nativeTag);
Expand Down Expand Up @@ -592,8 +589,7 @@ describe('ReactNative', () => {
'Learn more about using refs safely here: ' +
'https://fb.me/react-strict-mode-find-node' +
'\n in RCTView (at **)' +
'\n in IsInStrictMode (at **)' +
'\n in StrictMode (at **)',
'\n in IsInStrictMode (at **)',
]);
expect(match).toBe(child._nativeTag);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactCapturedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type {Fiber} from './ReactFiber';

import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';

export type CapturedValue<T> = {|
value: T,
Expand Down
6 changes: 2 additions & 4 deletions packages/react-reconciler/src/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ import {
createFiberFromPortal,
} from './ReactFiber';
import {emptyRefsObject} from './ReactFiberClassComponent';
import {
getCurrentFiberStackInDev,
getStackByFiberInDevAndProd,
} from './ReactCurrentFiber';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
import {getCurrentFiberStackInDev} from './ReactCurrentFiber';
import {isCompatibleFamilyForHotReloading} from './ReactFiberHotReloading';
import {StrictMode} from './ReactTypeOfMode';

Expand Down
41 changes: 1 addition & 40 deletions packages/react-reconciler/src/ReactCurrentFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,11 @@
import type {Fiber} from './ReactFiber';

import ReactSharedInternals from 'shared/ReactSharedInternals';
import {
HostRoot,
HostPortal,
HostText,
Fragment,
ContextProvider,
ContextConsumer,
} from './ReactWorkTags';
import describeComponentFrame from 'shared/describeComponentFrame';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
import getComponentName from 'shared/getComponentName';

const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;

function describeFiber(fiber: Fiber): string {
switch (fiber.tag) {
case HostRoot:
case HostPortal:
case HostText:
case Fragment:
case ContextProvider:
case ContextConsumer:
return '';
default:
const owner = fiber._debugOwner;
const source = fiber._debugSource;
const name = getComponentName(fiber.type);
let ownerName = null;
if (owner) {
ownerName = getComponentName(owner.type);
}
return describeComponentFrame(name, source, ownerName);
}
}

export function getStackByFiberInDevAndProd(workInProgress: Fiber): string {
let info = '';
let node = workInProgress;
do {
info += describeFiber(node);
node = node.return;
} while (node);
return info;
}

export let current: Fiber | null = null;
export let isRendering: boolean = false;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import getComponentName from 'shared/getComponentName';
import invariant from 'shared/invariant';

import {onCommitUnmount} from './ReactFiberDevToolsHook';
import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
import {resolveDefaultProps} from './ReactFiberLazyComponent';
import {
getCommitTime,
Expand Down
72 changes: 72 additions & 0 deletions packages/react-reconciler/src/ReactFiberComponentStack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import type {Fiber} from './ReactFiber';

import {
HostComponent,
LazyComponent,
SuspenseComponent,
SuspenseListComponent,
FunctionComponent,
IndeterminateComponent,
ForwardRef,
MemoComponent,
SimpleMemoComponent,
Block,
ClassComponent,
} from './ReactWorkTags';
import {
describeBuiltInComponentFrame,
describeFunctionComponentFrame,
describeClassComponentFrame,
} from 'shared/ReactComponentStackFrame';

function describeFiber(fiber: Fiber): string {
const owner: null | Function = __DEV__
? fiber._debugOwner
? fiber._debugOwner.type
: null
: null;
const source = __DEV__ ? fiber._debugSource : null;
switch (fiber.tag) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The list of things that get included was kind of arbitrary and not fully consistent before because it was filtered in Fiber but not in SSR. This list seems like the most commonly useful.

case HostComponent:
return describeBuiltInComponentFrame(fiber.type, source, owner);
case LazyComponent:
return describeBuiltInComponentFrame('Lazy', source, owner);
case SuspenseComponent:
return describeBuiltInComponentFrame('Suspense', source, owner);
case SuspenseListComponent:
return describeBuiltInComponentFrame('SuspenseList', source, owner);
case FunctionComponent:
case IndeterminateComponent:
case SimpleMemoComponent:
return describeFunctionComponentFrame(fiber.type, source, owner);
case ForwardRef:
return describeFunctionComponentFrame(fiber.type.render, source, owner);
case MemoComponent:
return describeFunctionComponentFrame(fiber.type.type, source, owner);
case Block:
return describeFunctionComponentFrame(fiber.type._render, source, owner);
case ClassComponent:
return describeClassComponentFrame(fiber.type, source, owner);
default:
return '';
}
}

export function getStackByFiberInDevAndProd(workInProgress: Fiber): string {
let info = '';
let node = workInProgress;
do {
info += describeFiber(node);
node = node.return;
} while (node);
return info;
}
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberReconciler.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ import {
IsThisRendererActing,
} from './ReactFiberWorkLoop';
import {createUpdate, enqueueUpdate} from './ReactUpdateQueue';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
import {
getStackByFiberInDevAndProd,
isRendering as ReactCurrentFiberIsRendering,
current as ReactCurrentFiberCurrent,
} from './ReactCurrentFiber';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberThrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
ForceUpdate,
enqueueUpdate,
} from './ReactUpdateQueue';
import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
import {markFailedErrorBoundaryForHotReloading} from './ReactFiberHotReloading';
import {
suspenseStackCursor,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ import {
// DEV stuff
import getComponentName from 'shared/getComponentName';
import ReactStrictModeWarnings from './ReactStrictModeWarnings';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';
import {
isRendering as ReactCurrentDebugFiberIsRenderingInDEV,
resetCurrentFiber as resetCurrentDebugFiberInDEV,
setCurrentFiber as setCurrentDebugFiberInDEV,
getStackByFiberInDevAndProd,
} from './ReactCurrentFiber';
import {
invokeGuardedCallback,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactStrictModeWarnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import type {Fiber} from './ReactFiber';

import {getStackByFiberInDevAndProd} from './ReactCurrentFiber';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';

import getComponentName from 'shared/getComponentName';
import {StrictMode} from './ReactTypeOfMode';
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/ReactDebugCurrentFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import type {ReactElement} from 'shared/ReactElementType';

import describeComponentFrame from 'shared/describeComponentFrame';
import getComponentName from 'shared/getComponentName';
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';

const ReactDebugCurrentFrame = {};

Expand Down Expand Up @@ -38,12 +37,11 @@ if (__DEV__) {

// Add an extra top frame while an element is being validated
if (currentlyValidatingElement) {
const name = getComponentName(currentlyValidatingElement.type);
const owner = currentlyValidatingElement._owner;
stack += describeComponentFrame(
name,
stack += describeUnknownElementTypeFrameInDEV(
currentlyValidatingElement.type,
currentlyValidatingElement._source,
owner && getComponentName(owner.type),
owner ? owner.type : null,
);
}

Expand Down
Loading