MCPcopy Create free account
hub / github.com/docker/getting-started / polyfill

Function polyfill

app/src/static/js/react-bootstrap.js:8028–8104  ·  view source on GitHub ↗
(Component)

Source from the content-addressed store, hash-verified

8026componentWillUpdate.__suppressDeprecationWarning = true;
8027
8028function polyfill(Component) {
8029 var prototype = Component.prototype;
8030
8031 if (!prototype || !prototype.isReactComponent) {
8032 throw new Error('Can only polyfill class components');
8033 }
8034
8035 if (typeof Component.getDerivedStateFromProps !== 'function' && typeof prototype.getSnapshotBeforeUpdate !== 'function') {
8036 return Component;
8037 } // If new component APIs are defined, "unsafe" lifecycles won't be called.
8038 // Error if any of these lifecycles are present,
8039 // Because they would work differently between older and newer (16.3+) versions of React.
8040
8041
8042 var foundWillMountName = null;
8043 var foundWillReceivePropsName = null;
8044 var foundWillUpdateName = null;
8045
8046 if (typeof prototype.componentWillMount === 'function') {
8047 foundWillMountName = 'componentWillMount';
8048 } else if (typeof prototype.UNSAFE_componentWillMount === 'function') {
8049 foundWillMountName = 'UNSAFE_componentWillMount';
8050 }
8051
8052 if (typeof prototype.componentWillReceiveProps === 'function') {
8053 foundWillReceivePropsName = 'componentWillReceiveProps';
8054 } else if (typeof prototype.UNSAFE_componentWillReceiveProps === 'function') {
8055 foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
8056 }
8057
8058 if (typeof prototype.componentWillUpdate === 'function') {
8059 foundWillUpdateName = 'componentWillUpdate';
8060 } else if (typeof prototype.UNSAFE_componentWillUpdate === 'function') {
8061 foundWillUpdateName = 'UNSAFE_componentWillUpdate';
8062 }
8063
8064 if (foundWillMountName !== null || foundWillReceivePropsName !== null || foundWillUpdateName !== null) {
8065 var componentName = Component.displayName || Component.name;
8066 var newApiName = typeof Component.getDerivedStateFromProps === 'function' ? 'getDerivedStateFromProps()' : 'getSnapshotBeforeUpdate()';
8067 throw Error('Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' + componentName + ' uses ' + newApiName + ' but also contains the following legacy lifecycles:' + (foundWillMountName !== null ? '\n ' + foundWillMountName : '') + (foundWillReceivePropsName !== null ? '\n ' + foundWillReceivePropsName : '') + (foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '') + '\n\nThe above lifecycles should be removed. Learn more about this warning here:\n' + 'https://fb.me/react-async-component-lifecycle-hooks');
8068 } // React <= 16.2 does not support static getDerivedStateFromProps.
8069 // As a workaround, use cWM and cWRP to invoke the new static lifecycle.
8070 // Newer versions of React will ignore these lifecycles if gDSFP exists.
8071
8072
8073 if (typeof Component.getDerivedStateFromProps === 'function') {
8074 prototype.componentWillMount = componentWillMount;
8075 prototype.componentWillReceiveProps = componentWillReceiveProps;
8076 } // React <= 16.2 does not support getSnapshotBeforeUpdate.
8077 // As a workaround, use cWU to invoke the new lifecycle.
8078 // Newer versions of React will ignore that lifecycle if gSBU exists.
8079
8080
8081 if (typeof prototype.getSnapshotBeforeUpdate === 'function') {
8082 if (typeof prototype.componentDidUpdate !== 'function') {
8083 throw new Error('Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype');
8084 }
8085

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…