Skip to content

Commit

Permalink
Remove object-assign polyfill (#23351)
Browse files Browse the repository at this point in the history
* Remove object-assign polyfill

We really rely on a more modern environment where this is typically
polyfilled anyway and we don't officially support IE with more extensive
polyfilling anyway. So all environments should have the native version
by now.

* Use shared/assign instead of Object.assign in code

This is so that we have one cached local instance in the bundle.

Ideally we should have a compile do this for us but we already follow
this pattern with hasOwnProperty, isArray, Object.is etc.

* Transform Object.assign to now use shared/assign

We need this to use the shared instance when Object.spread is used.
  • Loading branch information
sebmarkbage committed Feb 24, 2022
1 parent b3f3da2 commit 1ad8d81
Show file tree
Hide file tree
Showing 45 changed files with 73 additions and 156 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"minimist": "^1.2.3",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"object-assign": "^4.1.1",
"pacote": "^10.3.0",
"prettier": "1.19.1",
"prop-types": "^15.6.2",
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"react": "^17.0.0",
"react-test-renderer": "^17.0.0"
},
"dependencies": {
"object-assign": "^4.1.1"
},
"files": [
"LICENSE",
"README.md",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-art/npm/Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict';

var assign = require('object-assign');
var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-art/npm/Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

'use strict';

var assign = require('object-assign');
var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');
Expand Down
2 changes: 1 addition & 1 deletion packages/react-art/npm/Wedge.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

'use strict';

var assign = require('object-assign');
var assign = Object.assign;
var PropTypes = require('prop-types');
var React = require('react');
var ReactART = require('react-art');
Expand Down
1 change: 0 additions & 1 deletion packages/react-art/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"art": "^0.10.1",
"create-react-class": "^15.6.2",
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1",
"scheduler": "^0.20.1"
},
"peerDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions packages/react-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"react": "^17.0.0"
},
"dependencies": {
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1"
"loose-envify": "^1.1.0"
},
"browserify": {
"transform": [
Expand Down
3 changes: 1 addition & 2 deletions packages/react-debug-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"react": "^17.0.0"
},
"dependencies": {
"error-stack-parser": "^2.0.2",
"object-assign": "^4.1.1"
"error-stack-parser": "^2.0.2"
}
}
3 changes: 2 additions & 1 deletion packages/react-debug-tools/src/ReactDebugHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type {
} from 'react-reconciler/src/ReactInternalTypes';

import ErrorStackParser from 'error-stack-parser';
import assign from 'shared/assign';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {
FunctionComponent,
Expand Down Expand Up @@ -720,7 +721,7 @@ function inspectHooksOfForwardRef<Props, Ref>(
function resolveDefaultProps(Component, baseProps) {
if (Component && Component.defaultProps) {
// Resolve default props. Taken from ReactElement
const props = Object.assign({}, baseProps);
const props = assign({}, baseProps);
const defaultProps = Component.defaultProps;
for (const propName in defaultProps) {
if (props[propName] === undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
* @flow
*/

import assign from 'object-assign';
import {getElementDimensions, getNestedBoundingClientRect} from '../utils';

const assign = Object.assign;

import type {DevToolsHook} from 'react-devtools-shared/src/backend/types';
import type {Rect} from '../utils';

Expand Down
1 change: 0 additions & 1 deletion packages/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"homepage": "https://reactjs.org/",
"dependencies": {
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1",
"scheduler": "^0.20.1"
},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom/src/client/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {getToStringValue, toString} from './ToStringValue';
import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
import {updateValueIfChanged} from './inputValueTracking';
import getActiveElement from './getActiveElement';
import assign from 'shared/assign';
import {disableInputAttributeSyncing} from 'shared/ReactFeatureFlags';
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';

Expand Down Expand Up @@ -62,7 +63,7 @@ export function getHostProps(element: Element, props: Object) {
const node = ((element: any): InputWithWrapperState);
const checked = props.checked;

const hostProps = Object.assign({}, props, {
const hostProps = assign({}, props, {
defaultChecked: undefined,
defaultValue: undefined,
value: undefined,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom/src/client/ReactDOMSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {getCurrentFiberOwnerNameInDevOrNull} from 'react-reconciler/src/ReactCur

import {checkControlledValueProps} from '../shared/ReactControlledValuePropTypes';
import {getToStringValue, toString} from './ToStringValue';
import assign from 'shared/assign';
import isArray from 'shared/isArray';

let didWarnValueDefaultValue;
Expand Down Expand Up @@ -134,7 +135,7 @@ function updateOptions(
*/

export function getHostProps(element: Element, props: Object) {
return Object.assign({}, props, {
return assign({}, props, {
value: undefined,
});
}
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom/src/events/SyntheticEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/* eslint valid-typeof: 0 */

import assign from 'shared/assign';
import getEventCharCode from './getEventCharCode';

type EventInterfaceType = {
Expand Down Expand Up @@ -78,7 +79,7 @@ function createSyntheticEvent(Interface: EventInterfaceType) {
return this;
}

Object.assign(SyntheticBaseEvent.prototype, {
assign(SyntheticBaseEvent.prototype, {
preventDefault: function() {
this.defaultPrevented = true;
const event = this.nativeEvent;
Expand Down
21 changes: 11 additions & 10 deletions packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import warnValidStyle from '../shared/warnValidStyle';
import {validateProperties as validateARIAProperties} from '../shared/ReactDOMInvalidARIAHook';
import {validateProperties as validateInputProperties} from '../shared/ReactDOMNullInputValuePropHook';
import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook';
import assign from 'shared/assign';
import hasOwnProperty from 'shared/hasOwnProperty';

// Based on reading the React.Children implementation. TODO: type this somewhere?
Expand Down Expand Up @@ -563,7 +564,7 @@ function resolve(
}

if (partialState != null) {
inst.state = Object.assign({}, inst.state, partialState);
inst.state = assign({}, inst.state, partialState);
}
}
} else {
Expand Down Expand Up @@ -695,9 +696,9 @@ function resolve(
if (partialState != null) {
if (dontMutate) {
dontMutate = false;
nextState = Object.assign({}, nextState, partialState);
nextState = assign({}, nextState, partialState);
} else {
Object.assign(nextState, partialState);
assign(nextState, partialState);
}
}
}
Expand Down Expand Up @@ -745,7 +746,7 @@ function resolve(
}
}
if (childContext) {
context = Object.assign({}, context, childContext);
context = assign({}, context, childContext);
}
}
}
Expand Down Expand Up @@ -1192,7 +1193,7 @@ class ReactDOMServerRenderer {
const nextChildren = [
React.createElement(
elementType.type,
Object.assign({ref: element.ref}, element.props),
assign({ref: element.ref}, element.props),
),
];
const frame: Frame = {
Expand Down Expand Up @@ -1291,7 +1292,7 @@ class ReactDOMServerRenderer {
const nextChildren = [
React.createElement(
result,
Object.assign({ref: element.ref}, element.props),
assign({ref: element.ref}, element.props),
),
];
const frame: Frame = {
Expand Down Expand Up @@ -1413,7 +1414,7 @@ class ReactDOMServerRenderer {
}
}

props = Object.assign(
props = assign(
{
type: undefined,
},
Expand Down Expand Up @@ -1485,7 +1486,7 @@ class ReactDOMServerRenderer {
if (__DEV__) {
checkFormFieldValueStringCoercion(initialValue);
}
props = Object.assign({}, props, {
props = assign({}, props, {
value: undefined,
children: '' + initialValue,
});
Expand Down Expand Up @@ -1531,7 +1532,7 @@ class ReactDOMServerRenderer {
}
this.currentSelectValue =
props.value != null ? props.value : props.defaultValue;
props = Object.assign({}, props, {
props = assign({}, props, {
value: undefined,
});
} else if (tag === 'option') {
Expand Down Expand Up @@ -1577,7 +1578,7 @@ class ReactDOMServerRenderer {
selected = '' + selectValue === value;
}

props = Object.assign(
props = assign(
{
selected: undefined,
},
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
rethrowCaughtError,
invokeGuardedCallbackAndCatchFirstError,
} from 'shared/ReactErrorUtils';
import assign from 'shared/assign';
import isArray from 'shared/isArray';

// Keep in sync with ReactDOM.js:
Expand Down Expand Up @@ -596,7 +597,7 @@ function makeSimulator(eventType) {
// Since we aren't using pooling, always persist the event. This will make
// sure it's marked and won't warn when setting additional properties.
event.persist();
Object.assign(event, eventData);
assign(event, eventData);

if (directDispatchEventTypes.has(eventType)) {
accumulateDirectDispatchesSingle(event);
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"directory": "packages/react-native-renderer"
},
"dependencies": {
"object-assign": "^4.1.1",
"scheduler": "^0.11.0"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/* eslint valid-typeof: 0 */

import assign from 'shared/assign';

const EVENT_POOL_SIZE = 10;

/**
Expand Down Expand Up @@ -110,7 +112,7 @@ function SyntheticEvent(
return this;
}

Object.assign(SyntheticEvent.prototype, {
assign(SyntheticEvent.prototype, {
preventDefault: function() {
this.defaultPrevented = true;
const event = this.nativeEvent;
Expand Down Expand Up @@ -236,11 +238,11 @@ SyntheticEvent.extend = function(Interface) {
function Class() {
return Super.apply(this, arguments);
}
Object.assign(prototype, Class.prototype);
assign(prototype, Class.prototype);
Class.prototype = prototype;
Class.prototype.constructor = Class;

Class.Interface = Object.assign({}, Super.Interface, Interface);
Class.Interface = assign({}, Super.Interface, Interface);
Class.extend = Super.extend;
addEventPoolingTo(Class);

Expand Down
1 change: 0 additions & 1 deletion packages/react-noop-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"license": "MIT",
"dependencies": {
"object-assign": "^4.1.1",
"react-reconciler": "*",
"react-client": "*",
"react-server": "*"
Expand Down
1 change: 0 additions & 1 deletion packages/react-reconciler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"dependencies": {
"loose-envify": "^1.1.0",
"object-assign": "^4.1.1",
"scheduler": "^0.20.1"
},
"browserify": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {get as getInstance, set as setInstance} from 'shared/ReactInstanceMap';
import shallowEqual from 'shared/shallowEqual';
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
import getComponentNameFromType from 'shared/getComponentNameFromType';
import assign from 'shared/assign';
import isArray from 'shared/isArray';
import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols';

Expand Down Expand Up @@ -186,7 +187,7 @@ function applyDerivedStateFromProps(
const memoizedState =
partialState === null || partialState === undefined
? prevState
: Object.assign({}, prevState, partialState);
: assign({}, prevState, partialState);
workInProgress.memoizedState = memoizedState;

// Once the update queue is empty, persist the derived state onto the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {get as getInstance, set as setInstance} from 'shared/ReactInstanceMap';
import shallowEqual from 'shared/shallowEqual';
import getComponentNameFromFiber from 'react-reconciler/src/getComponentNameFromFiber';
import getComponentNameFromType from 'shared/getComponentNameFromType';
import assign from 'shared/assign';
import isArray from 'shared/isArray';
import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols';

Expand Down Expand Up @@ -186,7 +187,7 @@ function applyDerivedStateFromProps(
const memoizedState =
partialState === null || partialState === undefined
? prevState
: Object.assign({}, prevState, partialState);
: assign({}, prevState, partialState);
workInProgress.memoizedState = memoizedState;

// Once the update queue is empty, persist the derived state onto the
Expand Down
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiberLazyComponent.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* @flow
*/

import assign from 'shared/assign';

export function resolveDefaultProps(Component: any, baseProps: Object): Object {
if (Component && Component.defaultProps) {
// Resolve default props. Taken from ReactElement
const props = Object.assign({}, baseProps);
const props = assign({}, baseProps);
const defaultProps = Component.defaultProps;
for (const propName in defaultProps) {
if (props[propName] === undefined) {
Expand Down
4 changes: 3 additions & 1 deletion packages/react-reconciler/src/ReactFiberLazyComponent.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
* @flow
*/

import assign from 'shared/assign';

export function resolveDefaultProps(Component: any, baseProps: Object): Object {
if (Component && Component.defaultProps) {
// Resolve default props. Taken from ReactElement
const props = Object.assign({}, baseProps);
const props = assign({}, baseProps);
const defaultProps = Component.defaultProps;
for (const propName in defaultProps) {
if (props[propName] === undefined) {
Expand Down
Loading

0 comments on commit 1ad8d81

Please sign in to comment.