Skip to content

Commit

Permalink
refactor: prefix lifecycle methods with UNSAFE_
Browse files Browse the repository at this point in the history
Refs #7341
  • Loading branch information
char0n committed Sep 13, 2021
1 parent 4aae4b1 commit e7c5422
Show file tree
Hide file tree
Showing 18 changed files with 291 additions and 30,739 deletions.
30,974 changes: 263 additions & 30,711 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/core/components/content-type.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ContentType extends React.Component {
}
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if(!nextProps.contentTypes || !nextProps.contentTypes.size) {
return
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/components/examples-select-value-retainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
}

_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`
const { examples } = props || this.props
return stringifyUnlessList(
Expand All @@ -126,7 +126,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
}

_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`
const { currentKey } = props || this.props
return this._getValueForExample(currentKey, props || this.props)
Expand Down Expand Up @@ -169,7 +169,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
}
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
// update `lastUserEditedValue` as new currentUserInput values come in

const {
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/examples-select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class ExamplesSelect extends React.PureComponent {
}
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
const { currentExampleKey, examples } = nextProps
if (examples !== this.props.examples && !examples.has(currentExampleKey)) {
// examples have changed from under us, and the currentExampleKey is no longer
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/layout-utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export class Select extends React.Component {
onChange && onChange(value)
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
// TODO: this puts us in a weird area btwn un/controlled selection... review
if(nextProps.value !== this.props.value) {
this.setState({ value: nextProps.value })
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/model-collapse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class ModelCollapse extends Component {
}
}

componentWillReceiveProps(nextProps){
UNSAFE_componentWillReceiveProps(nextProps){
if(this.props.expanded !== nextProps.expanded){
this.setState({expanded: nextProps.expanded})
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/components/model-example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class ModelExample extends React.Component {
})
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (
nextProps.isExecute &&
!this.props.isExecute &&
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/online-validator-badge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class OnlineValidatorBadge extends React.Component {
return urlObject.toString()
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
let { getConfigs } = nextProps
let { validatorUrl } = getConfigs()

Expand Down Expand Up @@ -91,7 +91,7 @@ class ValidatorImage extends React.Component {
img.src = this.props.src
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.src !== this.props.src) {
const img = new Image()
img.onload = () => {
Expand Down
12 changes: 6 additions & 6 deletions src/core/components/param-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class ParamBody extends PureComponent {
this.updateValues.call(this, this.props)
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
this.updateValues.call(this, nextProps)
}

Expand Down Expand Up @@ -140,11 +140,11 @@ export default class ParamBody extends PureComponent {
}
<label htmlFor="">
<span>Parameter content type</span>
<ContentType
value={ consumesValue }
contentTypes={ consumes }
onChange={onChangeConsumes}
className="body-param-content-type"
<ContentType
value={ consumesValue }
contentTypes={ consumes }
onChange={onChangeConsumes}
className="body-param-content-type"
ariaLabel="Parameter content type" />
</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/parameter-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ParameterRow extends Component {
this.setDefaultValue()
}

componentWillReceiveProps(props) {
UNSAFE_componentWillReceiveProps(props) {
let { specSelectors, pathMethod, rawParam } = props
let isOAS3 = specSelectors.isOAS3()

Expand Down Expand Up @@ -127,7 +127,7 @@ export default class ParameterRow extends Component {
: (schema && schema.getIn(["default"]))
} else if (specSelectors.isOAS3()) {
const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey())
initialValue =
initialValue =
paramWithMeta.getIn(["examples", currentExampleKey, "value"]) !== undefined
? paramWithMeta.getIn(["examples", currentExampleKey, "value"])
: paramWithMeta.getIn(["content", parameterMediaType, "example"]) !== undefined
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/schemes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export default class Schemes extends React.Component {
method: PropTypes.string,
}

componentWillMount() {
UNSAFE_componentWillMount() {
let { schemes } = this.props

//fire 'change' event to set default 'value' of select
this.setScheme(schemes.first())
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
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,
// then fire 'change' event and select the first scheme in the list of options
Expand Down
2 changes: 1 addition & 1 deletion src/core/containers/OperationContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class OperationContainer extends PureComponent {
}
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
const { response, isShown } = nextProps
const resolvedSubtree = this.getResolvedSubtree()

Expand Down
2 changes: 1 addition & 1 deletion src/core/json-schema-components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class JsonSchema_array extends PureComponent {
this.state = { value: valueOrEmptyList(props.value), schema: props.schema}
}

componentWillReceiveProps(props) {
UNSAFE_componentWillReceiveProps(props) {
const value = valueOrEmptyList(props.value)
if(value !== this.state.value)
this.setState({ value })
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/oas3/components/request-body-editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class RequestBodyEditor extends PureComponent {
}, () => this.onChange(inputValue))
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
if(
this.props.value !== nextProps.value &&
nextProps.value !== this.state.value
Expand Down
2 changes: 1 addition & 1 deletion src/core/plugins/oas3/components/servers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class Servers extends React.Component {
this.setServer(servers.first().get("url"))
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
let {
servers,
setServerVariableValue,
Expand Down
4 changes: 2 additions & 2 deletions src/core/plugins/view/root-injects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const makeMappedContainer = (getSystem, getStore, memGetComponent, getCom
handleProps(getSystem, mapping, props, {})
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
handleProps(getSystem, mapping, nextProps, this.props)
}

Expand All @@ -76,7 +76,7 @@ const createClass = component => class extends Component {
}
}

const Fallback = ({
const Fallback = ({
name // eslint-disable-line react/prop-types
}) => <div className="fallback">😱 <i>Could not render { name === "t" ? "this component" : name }, see the console.</i></div>

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/topbar/topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Topbar extends React.Component {
this.state = { url: props.specSelectors.url(), selectedIndex: 0 }
}

componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps) {
this.setState({ url: nextProps.specSelectors.url() })
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/components/schemes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("<Schemes/>", function(){
expect(setSchemeSpy.mock.calls.length).toEqual(1)

// After an update
wrapper.instance().componentWillReceiveProps(props)
wrapper.instance().UNSAFE_componentWillReceiveProps(props)

// Should not be called again, since `currentScheme` is in schemes
expect(setSchemeSpy.mock.calls.length).toEqual(1)
Expand Down

0 comments on commit e7c5422

Please sign in to comment.