-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make "key" optional for performance #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If we make data fetching part of the router by default, I'd push for not assigning keys by default since components will be purer by default and the router can take care of re-fetching and passing the new data down (which is the logic that you normally might have in a componentDidUpdate). |
This one has been biting me a bit, because I have a scrolling list on the left, and the details for the selected item on the right. I need the url to update when you click a new item, which works, but then the list on the left is scrolled back to the top because the dom was thrown out. In reality, all that's changed is the text content of ~10 elements on the right hand side. |
yeah thats 👎 and exactly the case where this option would be 👍 |
Why don't we just make this a static method of the route handler? Default behavior would be to use no key, but the user could provide a |
Since users call activeRoute manually now, they can already pick a key themselves if they want. |
Wow, thanks @spicyj. That fixed my UX problem. In that case, it should just be a note in the README if anything. |
@spicyj and I have talked in irc about this a bit. When #57 is all sorted out, the implementation there may make it so we can just remove keys altogether. The reason we have them is to transition from and to the same route with different params; if we prescribe a convention around providing data, we will necessarily implement the hooks that will cause the view to update (w/o needing keys). |
<Routes useAutoKeys={false}/> ? |
Flags that change how the entire application behaves are hard to reason about, especially if the default allows you to be sloppier when writing the original code – when you switch the flag later on you'll have no idea what will break. I don't have a great idea for a better plan here though. Perhaps now that AsyncState exists we can encourage using that and never add keys? |
alright, will reopen if we head down that path and decide to come back to discuss this some more. |
reopening, I'm starting to think we should not be doing anything with keys. |
Why not? I honestly have no idea. |
We added the key in because a transition from My only concern is getting lots of tickets around "transitioning to the same route is broken". I guess we can just make it loud and clear in the README, examples, docs, everywhere, that you need |
Ah, now I remember. Can we do something fancy with shouldComponentUpdate: function (nextProps, nextState) {
return compareParams(this.props.params, nextProps.params);
} ? |
Yay! I don't think shouldComponentUpdate helps here though. |
I think it's fair to have people implement |
Not sure if this is possible in React but one thing that might be helpful would be to warn if, for a route that introduces a new param relative to its ancestors, |
gimme some of that sweet, sweet DOM diffing closes #97
follow #229 |
Right now we assign a key to a handler so that transitions from
/users/1
tousers/2
rerenders as expected without any extra work for the developer. However, we cause react to build up brand new dom with that transition.I would like to do something like
<Route useKey={false}/>
orRouter.disableKeys()
.This would require devs to implement
componentWillReceiveProps
on their route handlers when transitioning from/users/1
to/users/2
, but they will also get some perf improvements if they feel like they need them.Thoughts?
The text was updated successfully, but these errors were encountered: