refactor: prefix lifecycle methods with UNSAFE_

Refs #7341
This commit is contained in:
Vladimir Gorej
2021-08-12 08:57:56 +02:00
parent a9285c5aa1
commit 8c79e2a375
18 changed files with 80 additions and 30528 deletions

30552
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,7 @@ export default class ContentType extends React.Component {
} }
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
if(!nextProps.contentTypes || !nextProps.contentTypes.size) { if(!nextProps.contentTypes || !nextProps.contentTypes.size) {
return return
} }

View File

@@ -117,7 +117,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
} }
_getValueForExample = (exampleKey, props) => { _getValueForExample = (exampleKey, props) => {
// props are accepted so that this can be used in componentWillReceiveProps, // props are accepted so that this can be used in UNSAFE_componentWillReceiveProps,
// which has access to `nextProps` // which has access to `nextProps`
const { examples } = props || this.props const { examples } = props || this.props
return stringifyUnlessList( return stringifyUnlessList(
@@ -126,7 +126,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
} }
_getCurrentExampleValue = props => { _getCurrentExampleValue = props => {
// props are accepted so that this can be used in componentWillReceiveProps, // props are accepted so that this can be used in UNSAFE_componentWillReceiveProps,
// which has access to `nextProps` // which has access to `nextProps`
const { currentKey } = props || this.props const { currentKey } = props || this.props
return this._getValueForExample(currentKey, props || this.props) return this._getValueForExample(currentKey, props || this.props)
@@ -169,7 +169,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
} }
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
// update `lastUserEditedValue` as new currentUserInput values come in // update `lastUserEditedValue` as new currentUserInput values come in
const { const {

View File

@@ -78,7 +78,7 @@ export default class ExamplesSelect extends React.PureComponent {
} }
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
const { currentExampleKey, examples } = nextProps const { currentExampleKey, examples } = nextProps
if (examples !== this.props.examples && !examples.has(currentExampleKey)) { if (examples !== this.props.examples && !examples.has(currentExampleKey)) {
// examples have changed from under us, and the currentExampleKey is no longer // examples have changed from under us, and the currentExampleKey is no longer

View File

@@ -181,7 +181,7 @@ export class Select extends React.Component {
onChange && onChange(value) onChange && onChange(value)
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
// TODO: this puts us in a weird area btwn un/controlled selection... review // TODO: this puts us in a weird area btwn un/controlled selection... review
if(nextProps.value !== this.props.value) { if(nextProps.value !== this.props.value) {
this.setState({ value: nextProps.value }) this.setState({ value: nextProps.value })

View File

@@ -48,7 +48,7 @@ export default class ModelCollapse extends Component {
} }
} }
componentWillReceiveProps(nextProps){ UNSAFE_componentWillReceiveProps(nextProps){
if(this.props.expanded !== nextProps.expanded){ if(this.props.expanded !== nextProps.expanded){
this.setState({expanded: nextProps.expanded}) this.setState({expanded: nextProps.expanded})
} }

View File

@@ -45,7 +45,7 @@ export default class ModelExample extends React.Component {
}) })
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
if ( if (
nextProps.isExecute && nextProps.isExecute &&
!this.props.isExecute && !this.props.isExecute &&

View File

@@ -30,7 +30,7 @@ export default class OnlineValidatorBadge extends React.Component {
return urlObject.toString() return urlObject.toString()
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
let { getConfigs } = nextProps let { getConfigs } = nextProps
let { validatorUrl } = getConfigs() let { validatorUrl } = getConfigs()
@@ -91,7 +91,7 @@ class ValidatorImage extends React.Component {
img.src = this.props.src img.src = this.props.src
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.src !== this.props.src) { if (nextProps.src !== this.props.src) {
const img = new Image() const img = new Image()
img.onload = () => { img.onload = () => {

View File

@@ -43,7 +43,7 @@ export default class ParamBody extends PureComponent {
this.updateValues.call(this, this.props) this.updateValues.call(this, this.props)
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
this.updateValues.call(this, nextProps) this.updateValues.call(this, nextProps)
} }
@@ -140,11 +140,11 @@ export default class ParamBody extends PureComponent {
} }
<label htmlFor=""> <label htmlFor="">
<span>Parameter content type</span> <span>Parameter content type</span>
<ContentType <ContentType
value={ consumesValue } value={ consumesValue }
contentTypes={ consumes } contentTypes={ consumes }
onChange={onChangeConsumes} onChange={onChangeConsumes}
className="body-param-content-type" className="body-param-content-type"
ariaLabel="Parameter content type" /> ariaLabel="Parameter content type" />
</label> </label>
</div> </div>

View File

@@ -30,7 +30,7 @@ export default class ParameterRow extends Component {
this.setDefaultValue() this.setDefaultValue()
} }
componentWillReceiveProps(props) { UNSAFE_componentWillReceiveProps(props) {
let { specSelectors, pathMethod, rawParam } = props let { specSelectors, pathMethod, rawParam } = props
let isOAS3 = specSelectors.isOAS3() let isOAS3 = specSelectors.isOAS3()
@@ -127,7 +127,7 @@ export default class ParameterRow extends Component {
: (schema && schema.getIn(["default"])) : (schema && schema.getIn(["default"]))
} else if (specSelectors.isOAS3()) { } else if (specSelectors.isOAS3()) {
const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey()) const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey())
initialValue = initialValue =
paramWithMeta.getIn(["examples", currentExampleKey, "value"]) !== undefined paramWithMeta.getIn(["examples", currentExampleKey, "value"]) !== undefined
? paramWithMeta.getIn(["examples", currentExampleKey, "value"]) ? paramWithMeta.getIn(["examples", currentExampleKey, "value"])
: paramWithMeta.getIn(["content", parameterMediaType, "example"]) !== undefined : paramWithMeta.getIn(["content", parameterMediaType, "example"]) !== undefined

View File

@@ -11,14 +11,14 @@ export default class Schemes extends React.Component {
method: PropTypes.string, method: PropTypes.string,
} }
componentWillMount() { UNSAFE_componentWillMount() {
let { schemes } = this.props let { schemes } = this.props
//fire 'change' event to set default 'value' of select //fire 'change' event to set default 'value' of select
this.setScheme(schemes.first()) this.setScheme(schemes.first())
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
if ( !this.props.currentScheme || !nextProps.schemes.includes(this.props.currentScheme) ) { if ( !this.props.currentScheme || !nextProps.schemes.includes(this.props.currentScheme) ) {
// if we don't have a selected currentScheme or if our selected scheme is no longer an option, // if we don't have a selected currentScheme or if our selected scheme is no longer an option,
// then fire 'change' event and select the first scheme in the list of options // then fire 'change' event and select the first scheme in the list of options

View File

@@ -91,7 +91,7 @@ export default class OperationContainer extends PureComponent {
} }
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
const { response, isShown } = nextProps const { response, isShown } = nextProps
const resolvedSubtree = this.getResolvedSubtree() const resolvedSubtree = this.getResolvedSubtree()

View File

@@ -130,7 +130,7 @@ export class JsonSchema_array extends PureComponent {
this.state = { value: valueOrEmptyList(props.value), schema: props.schema} this.state = { value: valueOrEmptyList(props.value), schema: props.schema}
} }
componentWillReceiveProps(props) { UNSAFE_componentWillReceiveProps(props) {
const value = valueOrEmptyList(props.value) const value = valueOrEmptyList(props.value)
if(value !== this.state.value) if(value !== this.state.value)
this.setState({ value }) this.setState({ value })

View File

@@ -55,7 +55,7 @@ export default class RequestBodyEditor extends PureComponent {
}, () => this.onChange(inputValue)) }, () => this.onChange(inputValue))
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
if( if(
this.props.value !== nextProps.value && this.props.value !== nextProps.value &&
nextProps.value !== this.state.value nextProps.value !== this.state.value

View File

@@ -25,7 +25,7 @@ export default class Servers extends React.Component {
this.setServer(servers.first().get("url")) this.setServer(servers.first().get("url"))
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
let { let {
servers, servers,
setServerVariableValue, setServerVariableValue,

View File

@@ -50,7 +50,7 @@ export const makeMappedContainer = (getSystem, getStore, memGetComponent, getCom
handleProps(getSystem, mapping, props, {}) handleProps(getSystem, mapping, props, {})
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
handleProps(getSystem, mapping, nextProps, this.props) handleProps(getSystem, mapping, nextProps, this.props)
} }
@@ -76,7 +76,7 @@ const createClass = component => class extends Component {
} }
} }
const Fallback = ({ const Fallback = ({
name // eslint-disable-line react/prop-types name // eslint-disable-line react/prop-types
}) => <div className="fallback">😱 <i>Could not render { name === "t" ? "this component" : name }, see the console.</i></div> }) => <div className="fallback">😱 <i>Could not render { name === "t" ? "this component" : name }, see the console.</i></div>

View File

@@ -17,7 +17,7 @@ export default class Topbar extends React.Component {
this.state = { url: props.specSelectors.url(), selectedIndex: 0 } this.state = { url: props.specSelectors.url(), selectedIndex: 0 }
} }
componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps) {
this.setState({ url: nextProps.specSelectors.url() }) this.setState({ url: nextProps.specSelectors.url() })
} }

View File

@@ -61,7 +61,7 @@ describe("<Schemes/>", function(){
expect(setSchemeSpy.mock.calls.length).toEqual(1) expect(setSchemeSpy.mock.calls.length).toEqual(1)
// After an update // After an update
wrapper.instance().componentWillReceiveProps(props) wrapper.instance().UNSAFE_componentWillReceiveProps(props)
// Should not be called again, since `currentScheme` is in schemes // Should not be called again, since `currentScheme` is in schemes
expect(setSchemeSpy.mock.calls.length).toEqual(1) expect(setSchemeSpy.mock.calls.length).toEqual(1)