-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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
root.createBatch #11473
root.createBatch #11473
Conversation
Can you remind me why you didn't think the createBatch API was good and why you changed your mind? |
The main problem with my prerender PR (#11346) is that if you prerender multiple times, committing one update has the effect of also committing updates at the same or earlier expiration time, removing the guarantee that an update won't be flushed until the const work1 = root.prerender('a');
work1.then(onComplete1);
const work2 = root.prerender('b');
work2.then(onComplete2);
// Flush all work up to and including work2
work2.commit();
// Should onComplete1 have fired? Should work1 be aborted? Unclear. The But you could do this with the However, there are valid reasons why you might want to update a root twice at the same expiration time, like if you receive new props from the server before the previous props have completed. This isn't possible using the The const batch1 = root.createBatch();
batch1.render('a');
batch1.then(onComplete1);
const batch2 = root.createBatch();
batch2.render('b');
batch2.then(onComplete2);
// Update again at the same expiration time
batch2.render('c');
// Both `b` and `c` are flushed
// onComplete2 fires, but not onComplete1
batch2.commit(); |
2359e25
to
df28e9a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense but I'm going to need a moment to get comfortable with the amount of code that's here. Is there any thing we can do to hoist things out into a separate module?
let expirationTime; | ||
// Check if the top-level element is an async wrapper component. If so, | ||
// treat updates to the root as async. This is a bit weird but lets us | ||
// avoid a separate `renderAsync` API. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😃
This comment doesn't really make sense now does it?
What's the actual file size impact? |
@sebmarkbage I think the whole |
df28e9a
to
4f895b6
Compare
As this PR currently stands, it increases the ReactDOM prod bundle from 30.08 KB -> 31.3 KB |
That's like 0.3 preacts. That's quite significant for something that doesn't even do the actual work but is just plumbing. |
I think I can get it down a bit but the best way to offset it would be to remove legacy edge cases. |
Or move it into a separate package, but if this is the way to do async, then I don't know how much that really helps medium to long term. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, let's see if we can optimize it when it is in place.
It would nice to at least be able to DCE if the export is never referenced, and also the inverse. If the legacy APIs are never referenced.
What is DCE? |
dead code elimination |
API for batching top-level updates and deferring the commit. - `root.createBatch` creates a batch with an async expiration time associated with it. - `batch.render` updates the children that the batch renders. - `batch.then` resolves when the root has completed. - `batch.commit` synchronously flushes any remaining work and commits. No two batches can have the same expiration time. The only way to commit a batch is by calling its `commit` method. E.g. flushing one batch will not cause a different batch to also flush.
4f895b6
to
df9157b
Compare
@acdlite Can I ask that what's the different between |
I think the word 'defer' is not correct, event I don't use |
Another question is that it seems
|
API for batching top-level updates and deferring the commit. - `root.createBatch` creates a batch with an async expiration time associated with it. - `batch.render` updates the children that the batch renders. - `batch.then` resolves when the root has completed. - `batch.commit` synchronously flushes any remaining work and commits. No two batches can have the same expiration time. The only way to commit a batch is by calling its `commit` method. E.g. flushing one batch will not cause a different batch to also flush.
Alternative to #11346
API for batching top-level updates and deferring the commit.
root.createBatch
creates a batch with an async expiration time associated with it.batch.render
updates the children that the batch renders.batch.then
resolves when the root has completed.batch.commit
synchronously flushes any remaining work and commits.No two batches can have the same expiration time. The only way to commit a batch is by calling its
commit
method. E.g. flushing one batch will not cause a different batch to also flush.TODO: Specify error handling behavior.