-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Consider using unstable batched updates? #1091
Comments
@vincentriemer put together a notional example of how to use this with ReactDOM, or fall back to a noop in RN: https://gist.github.com/vincentriemer/1c761d9d31d85e9077cf82546ef62f5b |
Will this have any effect in 6.0? Perhaps those context updates could be batched, but that's going to be internal to React. And those should probably be sliced into separate units of work anyways. I do wonder how we would be able to signal to React that some are higher priority than others, but that's still a bunch of other |
Update batching is how React coalesces multiple That said, I'm not entirely sure where and how we would actually use it. Dan was trying to explain a bit over DM, but that's not a great medium. I've asked him to comment here tomorrow and explain in more detail. And no, react-redux/src/components/connectAdvanced.js Lines 177 to 179 in f0840f1
|
Is it even necessary nowadays anyways? |
Would that be set to a sane default, but user-overridable? |
So here's my understanding of how things work:
So, the reason why The question here is if there's a good way to leverage this so that Redux dispatches outside of React event handlers can be batched together. I've pinged @gaearon again and asked him to provide some more info. I don't want this to hold up v6 (which we'd like to push to final today), but it'd be nice to investigate this further and maybe have a way to use it more easily in a 6.1 release or something. The question of update priorities is somewhat related, but I don't think it's something we can really look into further until there's more progress on releasing Suspense features. |
I don't think this is true. I only see Again, I'm not quite sure what we could be doing here. Perhaps something around the subscription? But given that happens at the Provider level, I'm not sure what there is to batch. 🤷♂️ |
Coming from @markerikson Twitter post.
I believe that would depend on when those two
I think the use case doesn't occur often. Usually need if I need to call two class App extends React.Component {
state = { loading: false, number: 0 };
setRandomNumber() {
this.setState({ number: Math.random() });
}
handleClick = () => {
setTimeout(() => {
// Force one render
ReactDOM.unstable_batchedUpdates(() => {
this.setRandomNumber();
this.setState(({ loading }) => ({ loading: !loading }));
});
});
};
render() {
console.log('App');
return (
<div className="App">
<span>{this.state.loading && 'Loading...'}</span>
<Button onClick={this.handleClick}>Random Number</Button>
<div>{this.state.number}</div>
</div>
);
}
} Probably not that good of an example... |
Since there hasn't been any forward movement here and Dan hasn't provided an example of what he's suggesting, I'm going to close this out for now. I'm not sure what we could do here anyways... |
@gaearon contacted me and suggested that we should go ahead and use React's
unstable_batchedUpdates
API in version 6, and that "not using it from the start was a mistake".I haven't used it in practice myself, so I'm not sure what the tradeoffs are. The main thing I know is that it's part of ReactDOM, so I don't know how we'd handle this with React Native.
Thoughts?
/cc @timdorr , @cellog , @jimbolla .
The text was updated successfully, but these errors were encountered: