Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

fix(compat): upgrade Panel lifecycle #2287

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/next/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class extends React.Component {
}

componentWillReceiveProps() {
// @TODO: probably derived state
this.setState({ searchState: qs.parse(window.location.search.slice(1)) });
}

Expand Down
2 changes: 0 additions & 2 deletions examples/react-native/src/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ class Home extends Component {
};
}

componentWillReceiveProps() {}

onSearchStateChange = nextState => {
this.setState({ searchState: { ...this.state.searchState, ...nextState } });
};
Expand Down
1 change: 1 addition & 0 deletions examples/react-native/src/Price.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Range extends React.Component {
};
}
componentWillReceiveProps(sliderState) {
// @TODO: derived state
if (sliderState.canRefine) {
this.setState({
currentValues: {
Expand Down
1 change: 1 addition & 0 deletions examples/react-router-v3/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class App extends Component {
}

componentWillReceiveProps() {
// @TODO: derived state
this.setState({ searchState: qs.parse(this.props.router.location.query) });
}

Expand Down
1 change: 1 addition & 0 deletions examples/react-router/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class App extends Component {
}

componentWillReceiveProps(props) {
// @TODO: derived state
if (props.location !== this.props.location) {
this.setState({ searchState: urlToSearchState(props.location) });
}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-instantsearch-core/src/components/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Index extends Component {
}

componentWillMount() {
// @TODO: constructor
this.context.ais.onSearchParameters(
this.getSearchParameters.bind(this),
this.getChildContext(),
Expand All @@ -53,6 +54,7 @@ class Index extends Component {
}

componentWillReceiveProps(nextProps) {
// @TODO: DidUpdate
if (this.props.indexName !== nextProps.indexName) {
this.context.ais.widgetsManager.update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class InstantSearch extends Component {
}

componentWillReceiveProps(nextProps) {
// @TODO: DidUpdate
validateNextProps(this.props, nextProps);

if (this.props.indexName !== nextProps.indexName) {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-instantsearch-core/src/core/createConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default function createConnector(connectorDesc) {
}

componentWillMount() {
// @TODO: constructor
if (connectorDesc.getSearchParameters) {
this.context.ais.onSearchParameters(
connectorDesc.getSearchParameters.bind(this),
Expand Down Expand Up @@ -141,6 +142,7 @@ export default function createConnector(connectorDesc) {
}

componentWillReceiveProps(nextProps) {
// @TODO: split in Derived for state & DidUpdate
if (!isEqual(this.props, nextProps)) {
this.setState({
props: this.getProvidedProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function createInstantSearch(defaultAlgoliaClient, root) {
}

componentWillReceiveProps(nextProps) {
// @TODO: DidUpdate, but might be too late? If needs to be before rendering: derived State for client
const props = this.props;

if (nextProps.searchClient) {
Expand All @@ -88,6 +89,7 @@ export default function createInstantSearch(defaultAlgoliaClient, root) {
}

if (typeof this.client.addAlgoliaAgent === 'function') {
// @TODO: maybe DidUpdate if that's not too late, otherwise side effect in derived state
this.client.addAlgoliaAgent(`react-instantsearch ${version}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ class PanelCallbackHandler extends Component {
setCanRefine: PropTypes.func,
};

componentWillMount() {
componentDidMount() {
if (this.context.setCanRefine) {
this.context.setCanRefine(this.props.canRefine);
}
}

componentWillReceiveProps(nextProps) {
componentDidUpdate(prevProps) {
if (
this.context.setCanRefine &&
this.props.canRefine !== nextProps.canRefine
prevProps.canRefine !== this.props.canRefine
) {
this.context.setCanRefine(nextProps.canRefine);
this.context.setCanRefine(this.props.canRefine);
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/react-instantsearch-dom/src/components/RangeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class RawRangeInput extends Component {
}

componentWillReceiveProps(nextProps) {
// @TODO: Render, worst case in Derived State

// In [email protected] the call to setState on the inputs trigger this lifecycle hook
// because the context has changed (for react). I don't think that the bug is related
// to react because I failed to reproduce it with a simple hierarchy of components.
Expand Down
2 changes: 2 additions & 0 deletions packages/react-instantsearch-dom/src/components/SearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class SearchBox extends Component {
}

componentWillReceiveProps(nextProps) {
// @TODO: should component maybe be controlled, otherwise Derived

// Reset query when the searchParameters query has changed.
// This is kind of an anti-pattern (props in state), but it works here
// since we know for sure that searchParameters having changed means a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('PanelCallbackHandler', () => {
expect(wrapper).toMatchSnapshot();
});

describe('willMount', () => {
describe('didMount', () => {
it('expect to call setCanRefine when the context is given', () => {
const props = {
canRefine: true,
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('PanelCallbackHandler', () => {
});
});

describe('willReceiveProps', () => {
describe('didUpdate', () => {
it('expect to call setCanRefine when the context is given', () => {
const props = {
canRefine: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Range extends React.Component {
state = { currentValues: { min: this.props.min, max: this.props.max } };
componentWillReceiveProps(sliderState) {
// @TODO: Derived State, maybe render
if (sliderState.canRefine) {
this.setState({
currentValues: {
Expand Down
1 change: 1 addition & 0 deletions stories/3rdPartyIntegrations.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Range extends Component {
state = { currentValues: { min: this.props.min, max: this.props.max } };

componentWillReceiveProps(sliderState) {
// @TODO: Derived State, maybe render
if (sliderState.canRefine) {
this.setState({
currentValues: {
Expand Down
1 change: 1 addition & 0 deletions website/examples/tourism/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class Range extends Component {
state = { currentValues: { min: this.props.min, max: this.props.max } };

componentWillReceiveProps(sliderState) {
// @TODO: derived state
if (sliderState.canRefine) {
this.setState({
currentValues: {
Expand Down