mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Revert "React.pure automatically forwards ref" (#13887)
Reverts #13822. We're not sure we want to do this.
This commit is contained in:
+3
-4
@@ -242,7 +242,6 @@ function updatePureComponent(
|
||||
renderExpirationTime: ExpirationTime,
|
||||
) {
|
||||
const render = Component.render;
|
||||
const ref = workInProgress.ref;
|
||||
|
||||
if (
|
||||
current !== null &&
|
||||
@@ -253,7 +252,7 @@ function updatePureComponent(
|
||||
// Default to shallow comparison
|
||||
let compare = Component.compare;
|
||||
compare = compare !== null ? compare : shallowEqual;
|
||||
if (workInProgress.ref === current.ref && compare(prevProps, nextProps)) {
|
||||
if (compare(prevProps, nextProps)) {
|
||||
return bailoutOnAlreadyFinishedWork(
|
||||
current,
|
||||
workInProgress,
|
||||
@@ -268,10 +267,10 @@ function updatePureComponent(
|
||||
if (__DEV__) {
|
||||
ReactCurrentOwner.current = workInProgress;
|
||||
ReactCurrentFiber.setCurrentPhase('render');
|
||||
nextChildren = render(nextProps, ref);
|
||||
nextChildren = render(nextProps);
|
||||
ReactCurrentFiber.setCurrentPhase(null);
|
||||
} else {
|
||||
nextChildren = render(nextProps, ref);
|
||||
nextChildren = render(nextProps);
|
||||
}
|
||||
|
||||
// React DevTools reads this flag.
|
||||
|
||||
@@ -39,10 +39,10 @@ describe('pure', () => {
|
||||
// a lazy function component.
|
||||
sharedTests('normal', (...args) => {
|
||||
const Pure = React.pure(...args);
|
||||
function Indirection(props, ref) {
|
||||
return <Pure {...props} ref={ref} />;
|
||||
function Indirection(props) {
|
||||
return <Pure {...props} />;
|
||||
}
|
||||
return Promise.resolve(React.forwardRef(Indirection));
|
||||
return Promise.resolve(Indirection);
|
||||
});
|
||||
sharedTests('lazy', (...args) => Promise.resolve(React.pure(...args)));
|
||||
|
||||
@@ -195,65 +195,6 @@ describe('pure', () => {
|
||||
{withoutStack: true},
|
||||
);
|
||||
});
|
||||
|
||||
it('forwards ref', async () => {
|
||||
const {unstable_Suspense: Suspense} = React;
|
||||
const Transparent = pure((props, ref) => {
|
||||
return <div ref={ref} />;
|
||||
});
|
||||
const divRef = React.createRef();
|
||||
|
||||
ReactNoop.render(
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
<Transparent ref={divRef} />
|
||||
</Suspense>,
|
||||
);
|
||||
ReactNoop.flush();
|
||||
await Promise.resolve();
|
||||
ReactNoop.flush();
|
||||
expect(divRef.current.type).toBe('div');
|
||||
});
|
||||
|
||||
it('updates if only ref changes', async () => {
|
||||
const {unstable_Suspense: Suspense} = React;
|
||||
const Transparent = pure((props, ref) => {
|
||||
return [<Text key="text" text="Text" />, <div key="div" ref={ref} />];
|
||||
});
|
||||
|
||||
const divRef = React.createRef();
|
||||
const divRef2 = React.createRef();
|
||||
|
||||
ReactNoop.render(
|
||||
<Suspense fallback={<Text text="Loading..." />}>
|
||||
<Transparent ref={divRef} />
|
||||
</Suspense>,
|
||||
);
|
||||
expect(ReactNoop.flush()).toEqual(['Loading...']);
|
||||
await Promise.resolve();
|
||||
expect(ReactNoop.flush()).toEqual(['Text']);
|
||||
expect(divRef.current.type).toBe('div');
|
||||
expect(divRef2.current).toBe(null);
|
||||
|
||||
// Should re-render (new ref)
|
||||
ReactNoop.render(
|
||||
<Suspense>
|
||||
<Transparent ref={divRef2} />
|
||||
</Suspense>,
|
||||
);
|
||||
expect(ReactNoop.flush()).toEqual(['Text']);
|
||||
expect(divRef.current).toBe(null);
|
||||
expect(divRef2.current.type).toBe('div');
|
||||
|
||||
// Should not re-render (same ref)
|
||||
ReactNoop.render(
|
||||
<Suspense>
|
||||
<Transparent ref={divRef2} />
|
||||
</Suspense>,
|
||||
);
|
||||
expect(ReactNoop.flush()).toEqual([]);
|
||||
expect(divRef.current).toBe(null);
|
||||
expect(divRef2.current.type).toBe('div');
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user