Skip to content

rerender on props.url change#332

Open
halcaponey wants to merge 4 commits intopreactjs:mainfrom
halcaponey:master
Open

rerender on props.url change#332
halcaponey wants to merge 4 commits intopreactjs:mainfrom
halcaponey:master

Conversation

@halcaponey
Copy link
Copy Markdown

resolves #330

Comment thread src/index.js Outdated
return props.url!==this.props.url || props.onChange!==this.props.onChange;
}

componentWillReceiveProps(props) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge this with shouldComponentUpdate above.

	shouldComponentUpdate(props) {
		if (props.url && props.url!==this.state.url) this.routeTo(props.url);
		return !props.static || props.url!=this.props.url || props.onChange!=this.props.onChange;
	}

Comment thread src/index.js Outdated
}

componentWillReceiveProps(props) {
if (props.url && props.url!==this.state.url) this.routeTo(props.url) && setUrl(props.url);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing a new URL to <Router> should not call setUrl(), since doing so will change all other Routers on the page.

@developit
Copy link
Copy Markdown
Member

Sorry for the super long delay in reviewing this @halcaponey! Just a few things I think we can address to get this merged.

@developit
Copy link
Copy Markdown
Member

Update looks good. Only thing I want to check is if this is triggering a double-render when changing the URL prop. Ideally we'd propagate the state without forcing a second render, since the router is already being re-rendered with the new URL as a prop.

@halcaponey
Copy link
Copy Markdown
Author

The problem comes from !props.static being always true and since a change on the url prop triggers a setState which triggers a shouldComponentUpdate which returns true because the static prop is not defined.

What is the static prop used for ? It's only called in shouldComponentUpdate.

  • If it's false or undefined, shouldComponentUpdate will always return true.
  • if it's true then url prop and onChange prop will determine the result of shouldComponentUpdate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

updating url prop doesn't trigger an update

2 participants