mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Revert "Support writing to this.refs from userspace" (#28877)
Reverts facebook/react#28867 It broke some tests, reverting until we figure out why to avoid having too much delay in the sync.
This commit is contained in:
@@ -819,6 +819,7 @@ function mountClassInstance(
|
||||
const instance = workInProgress.stateNode;
|
||||
instance.props = newProps;
|
||||
instance.state = workInProgress.memoizedState;
|
||||
instance.refs = {};
|
||||
|
||||
initializeUpdateQueue(workInProgress);
|
||||
|
||||
|
||||
@@ -138,28 +138,4 @@ describe('ReactFiberRefs', () => {
|
||||
);
|
||||
expect(refProp).toBe('child');
|
||||
});
|
||||
|
||||
test('strings refs can be codemodded to callback refs', async () => {
|
||||
let app;
|
||||
class App extends React.Component {
|
||||
render() {
|
||||
app = this;
|
||||
return (
|
||||
<div
|
||||
prop="Hello!"
|
||||
ref={el => {
|
||||
// `refs` used to be a shared frozen object unless/until a string
|
||||
// ref attached by the reconciler, but it's not anymore so that we
|
||||
// can codemod string refs to userspace callback refs.
|
||||
this.refs.div = el;
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const root = ReactNoop.createRoot();
|
||||
await act(() => root.render(<App />));
|
||||
expect(app.refs.div.prop).toBe('Hello!');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,13 +8,19 @@
|
||||
import ReactNoopUpdateQueue from './ReactNoopUpdateQueue';
|
||||
import assign from 'shared/assign';
|
||||
|
||||
const emptyObject = {};
|
||||
if (__DEV__) {
|
||||
Object.freeze(emptyObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class helpers for the updating state of a component.
|
||||
*/
|
||||
function Component(props, context, updater) {
|
||||
this.props = props;
|
||||
this.context = context;
|
||||
this.refs = {};
|
||||
// If a component has string refs, we will assign a different object later.
|
||||
this.refs = emptyObject;
|
||||
// We initialize the default updater but the real one gets injected by the
|
||||
// renderer.
|
||||
this.updater = updater || ReactNoopUpdateQueue;
|
||||
@@ -127,7 +133,7 @@ function PureComponent(props, context, updater) {
|
||||
this.props = props;
|
||||
this.context = context;
|
||||
// If a component has string refs, we will assign a different object later.
|
||||
this.refs = {};
|
||||
this.refs = emptyObject;
|
||||
this.updater = updater || ReactNoopUpdateQueue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user