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 @@ -15,7 +15,7 @@ let React;
let ReactDOM;
let ReactDOMServer;
let forwardRef;
let pure;
let memo;
let yieldedValues;
let yieldValue;
let clearYields;
Expand All @@ -27,7 +27,7 @@ function initModules() {
ReactDOM = require('react-dom');
ReactDOMServer = require('react-dom/server');
forwardRef = React.forwardRef;
pure = React.pure;
memo = React.memo;

yieldedValues = [];
yieldValue = value => {
Expand Down Expand Up @@ -83,7 +83,7 @@ describe('ReactDOMServerIntegration', () => {
expect(div.textContent).toBe('Test');
});

describe('pure functional components', () => {
describe('memoized functional components', () => {
beforeEach(() => {
resetModules();
});
Expand All @@ -98,39 +98,39 @@ describe('ReactDOMServerIntegration', () => {
}

itRenders('basic render', async render => {
const PureCounter = pure(Counter);
const domNode = await render(<PureCounter count={0} />);
const MemoCounter = memo(Counter);
const domNode = await render(<MemoCounter count={0} />);
expect(domNode.textContent).toEqual('Count: 0');
});

itRenders('composition with forwardRef', async render => {
const RefCounter = (props, ref) => <Counter count={ref.current} />;
const PureRefCounter = pure(forwardRef(RefCounter));
const MemoRefCounter = memo(forwardRef(RefCounter));

const ref = React.createRef();
ref.current = 0;
await render(<PureRefCounter ref={ref} />);
await render(<MemoRefCounter ref={ref} />);

expect(clearYields()).toEqual(['Count: 0']);
});

itRenders('with comparator', async render => {
const PureCounter = pure(Counter, (oldProps, newProps) => false);
await render(<PureCounter count={0} />);
const MemoCounter = memo(Counter, (oldProps, newProps) => false);
await render(<MemoCounter count={0} />);
expect(clearYields()).toEqual(['Count: 0']);
});

itRenders(
'comparator functions are not invoked on the server',
async render => {
const PureCounter = React.pure(Counter, (oldProps, newProps) => {
const MemoCounter = React.memo(Counter, (oldProps, newProps) => {
yieldValue(
`Old count: ${oldProps.count}, New count: ${newProps.count}`,
);
return oldProps.count === newProps.count;
});

await render(<PureCounter count={0} />);
await render(<MemoCounter count={0} />);
expect(clearYields()).toEqual(['Count: 0']);
},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
REACT_PROVIDER_TYPE,
REACT_CONTEXT_TYPE,
REACT_LAZY_TYPE,
REACT_PURE_TYPE,
REACT_MEMO_TYPE,
} from 'shared/ReactSymbols';

import {
Expand Down Expand Up @@ -1002,7 +1002,7 @@ class ReactDOMServerRenderer {
this.stack.push(frame);
return '';
}
case REACT_PURE_TYPE: {
case REACT_MEMO_TYPE: {
const element: ReactElement = ((nextChild: any): ReactElement);
let nextChildren = [
React.createElement(
Expand Down
12 changes: 6 additions & 6 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
Profiler,
SuspenseComponent,
FunctionComponent,
PureComponent,
MemoComponent,
LazyComponent,
} from 'shared/ReactWorkTags';
import getComponentName from 'shared/getComponentName';
Expand All @@ -57,7 +57,7 @@ import {
REACT_CONTEXT_TYPE,
REACT_CONCURRENT_MODE_TYPE,
REACT_SUSPENSE_TYPE,
REACT_PURE_TYPE,
REACT_MEMO_TYPE,
REACT_LAZY_TYPE,
} from 'shared/ReactSymbols';

Expand Down Expand Up @@ -315,8 +315,8 @@ export function resolveLazyComponentTag(Component: Function): WorkTag {
if ($$typeof === REACT_FORWARD_REF_TYPE) {
return ForwardRef;
}
if ($$typeof === REACT_PURE_TYPE) {
return PureComponent;
if ($$typeof === REACT_MEMO_TYPE) {
return MemoComponent;
}
}
return IndeterminateComponent;
Expand Down Expand Up @@ -470,8 +470,8 @@ export function createFiberFromTypeAndProps(
case REACT_FORWARD_REF_TYPE:
fiberTag = ForwardRef;
break getTag;
case REACT_PURE_TYPE:
fiberTag = PureComponent;
case REACT_MEMO_TYPE:
fiberTag = MemoComponent;
break getTag;
case REACT_LAZY_TYPE:
fiberTag = LazyComponent;
Expand Down
28 changes: 14 additions & 14 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import {
ContextConsumer,
Profiler,
SuspenseComponent,
PureComponent,
SimplePureComponent,
MemoComponent,
SimpleMemoComponent,
LazyComponent,
} from 'shared/ReactWorkTags';
import {
Expand Down Expand Up @@ -231,7 +231,7 @@ function updateForwardRef(
return workInProgress.child;
}

function updatePureComponent(
function updateMemoComponent(
current: Fiber | null,
workInProgress: Fiber,
Component: any,
Expand All @@ -244,10 +244,10 @@ function updatePureComponent(
if (isSimpleFunctionComponent(type) && Component.compare === null) {
// If this is a plain function component without default props,
// and with only the default shallow comparison, we upgrade it
// to a SimplePureComponent to allow fast path updates.
workInProgress.tag = SimplePureComponent;
// to a SimpleMemoComponent to allow fast path updates.
workInProgress.tag = SimpleMemoComponent;
workInProgress.type = type;
return updateSimplePureComponent(
return updateSimpleMemoComponent(
current,
workInProgress,
type,
Expand Down Expand Up @@ -299,7 +299,7 @@ function updatePureComponent(
return newChild;
}

function updateSimplePureComponent(
function updateSimpleMemoComponent(
current: Fiber | null,
workInProgress: Fiber,
Component: any,
Expand Down Expand Up @@ -814,8 +814,8 @@ function mountLazyComponent(
);
break;
}
case PureComponent: {
child = updatePureComponent(
case MemoComponent: {
child = updateMemoComponent(
null,
workInProgress,
Component,
Expand All @@ -826,7 +826,7 @@ function mountLazyComponent(
break;
}
default: {
// This message intentionally doesn't metion ForwardRef or PureComponent
// This message intentionally doesn't metion ForwardRef or MemoComponent
// because the fact that it's a separate type of work is an
// implementation detail.
invariant(
Expand Down Expand Up @@ -1612,11 +1612,11 @@ function beginWork(
workInProgress,
renderExpirationTime,
);
case PureComponent: {
case MemoComponent: {
const type = workInProgress.type;
const unresolvedProps = workInProgress.pendingProps;
const resolvedProps = resolveDefaultProps(type.type, unresolvedProps);
return updatePureComponent(
return updateMemoComponent(
current,
workInProgress,
type,
Expand All @@ -1625,8 +1625,8 @@ function beginWork(
renderExpirationTime,
);
}
case SimplePureComponent: {
return updateSimplePureComponent(
case SimpleMemoComponent: {
return updateSimpleMemoComponent(
current,
workInProgress,
workInProgress.type,
Expand Down
8 changes: 4 additions & 4 deletions packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import {
Mode,
Profiler,
SuspenseComponent,
PureComponent,
SimplePureComponent,
MemoComponent,
SimpleMemoComponent,
LazyComponent,
} from 'shared/ReactWorkTags';
import {Placement, Ref, Update} from 'shared/ReactSideEffectTags';
Expand Down Expand Up @@ -540,7 +540,7 @@ function completeWork(
break;
case LazyComponent:
break;
case SimplePureComponent:
case SimpleMemoComponent:
case FunctionComponent:
break;
case ClassComponent: {
Expand Down Expand Up @@ -715,7 +715,7 @@ function completeWork(
break;
case ContextConsumer:
break;
case PureComponent:
case MemoComponent:
break;
default:
invariant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,13 @@ describe('ReactDebugFiberPerf', () => {
expect(getFlameChart()).toMatchSnapshot();
});

it('supports pure', () => {
const PureFoo = React.pure(function Foo() {
it('supports memo', () => {
const MemoFoo = React.memo(function Foo() {
return <div />;
});
ReactNoop.render(
<Parent>
<PureFoo />
<MemoFoo />
</Parent>,
);
ReactNoop.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let React;
let ReactFeatureFlags;
let ReactNoop;

describe('pure', () => {
describe('memo', () => {
beforeEach(() => {
jest.resetModules();
ReactFeatureFlags = require('shared/ReactFeatureFlags');
Expand All @@ -38,30 +38,30 @@ describe('pure', () => {
return {default: result};
}

// Tests should run against both the lazy and non-lazy versions of `pure`.
// Tests should run against both the lazy and non-lazy versions of `memo`.
// To make the tests work for both versions, we wrap the non-lazy version in
// a lazy function component.
sharedTests('normal', (...args) => {
const Pure = React.pure(...args);
const Memo = React.memo(...args);
function Indirection(props) {
return <Pure {...props} />;
return <Memo {...props} />;
}
return React.lazy(() => fakeImport(Indirection));
});
sharedTests('lazy', (...args) => {
const Pure = React.pure(...args);
return React.lazy(() => fakeImport(Pure));
const Memo = React.memo(...args);
return React.lazy(() => fakeImport(Memo));
});

function sharedTests(label, pure) {
function sharedTests(label, memo) {
describe(`${label}`, () => {
it('bails out on props equality', async () => {
const {unstable_Suspense: Suspense} = React;

function Counter({count}) {
return <Text text={count} />;
}
Counter = pure(Counter);
Counter = memo(Counter);

ReactNoop.render(
<Suspense fallback={<Text text="Loading..." />}>
Expand Down Expand Up @@ -108,7 +108,7 @@ describe('pure', () => {
const count = readContext(CountContext);
return <Text text={`${props.label}: ${count}`} />;
}
Counter = pure(Counter);
Counter = memo(Counter);

class Parent extends React.Component {
state = {count: 0};
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('pure', () => {
function Counter({count}) {
return <Text text={count} />;
}
Counter = pure(Counter, (oldProps, newProps) => {
Counter = memo(Counter, (oldProps, newProps) => {
ReactNoop.yield(
`Old count: ${oldProps.count}, New count: ${newProps.count}`,
);
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('pure', () => {
return <Text text={this.props.count + '' + this.props.suffix} />;
}
}
const Counter = pure(CounterInner);
const Counter = memo(CounterInner);

ReactNoop.render(
<Suspense fallback={<Text text="Loading..." />}>
Expand Down Expand Up @@ -224,8 +224,8 @@ describe('pure', () => {
});

it('warns if first argument is undefined', () => {
expect(() => pure()).toWarnDev(
'pure: The first argument must be a component. Instead ' +
expect(() => memo()).toWarnDev(
'memo: The first argument must be a component. Instead ' +
'received: undefined',
{withoutStack: true},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ exports[`ReactDebugFiberPerf supports portals 1`] = `
"
`;

exports[`ReactDebugFiberPerf supports pure 1`] = `
exports[`ReactDebugFiberPerf supports memo 1`] = `
"⚛ (Waiting for async callback... will force flush in 5250 ms)

⚛ (React Tree Reconciliation: Completed Root)
Expand Down
10 changes: 5 additions & 5 deletions packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
Mode,
ForwardRef,
Profiler,
PureComponent,
SimplePureComponent,
MemoComponent,
SimpleMemoComponent,
} from 'shared/ReactWorkTags';
import invariant from 'shared/invariant';
import ReactVersion from 'shared/ReactVersion';
Expand Down Expand Up @@ -167,7 +167,7 @@ function toTree(node: ?Fiber) {
rendered: childrenToTree(node.child),
};
case FunctionComponent:
case SimplePureComponent:
case SimpleMemoComponent:
return {
nodeType: 'component',
type: node.type,
Expand All @@ -192,7 +192,7 @@ function toTree(node: ?Fiber) {
case Mode:
case Profiler:
case ForwardRef:
case PureComponent:
case MemoComponent:
return childrenToTree(node.child);
default:
invariant(
Expand All @@ -208,7 +208,7 @@ const validWrapperTypes = new Set([
ClassComponent,
HostComponent,
ForwardRef,
PureComponent,
MemoComponent,
// Normally skipped, but used when there's more than one root child.
HostRoot,
]);
Expand Down
Loading