-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Different timing of updates between withSelect and useSelect #19199
Comments
This sounds like a bug to me 🤔 |
Sounds like an async mode thing right?
See #19007 (comment) and the following discussions. |
It could be related to Async mode, and yes selectors should be run again when the Async mode changes. |
I actually can't replicate this. Try these blocks: (function() {
wp.blocks.registerBlockType("test/test-with-select", {
title: "Test With Select",
category: "common",
edit: wp.data.withSelect(select => {
return {
blockCount: select("core/block-editor").getBlockCount()
};
})(function(props) {
return props.blockCount;
})
});
wp.blocks.registerBlockType("test/test-use-select", {
title: "Test Use Select",
category: "common",
edit: function() {
return wp.data.useSelect(
select => select("core/block-editor").getBlockCount(),
[]
);
}
});
})(); They work as expected. |
Can you clarify why this is the expected behavior? Edit: I guess so far as the original report, if this is necessary for those updates to be reflected, I can see why this is important. Maybe I'm misunderstanding the internals, but it seems to me there's some issue where a delayed update should be forced to run when the async value changes. That could be to the same effect as what you're suggesting? |
@aduth My idea here is that if something was async and becomes sync, we can't be certain that the current props are fresh so we need to run the selectors again when the isAsync value changes. It might not be necessary for the other way (isAsync becoming false). |
Well, if the props changed, there will be a queued update that will be flushed right? |
I'm wondering if there might be some issue with how this works or is expected to work. I mentioned similarly in #19205:
When #19205 is effective at least in ensuring that when |
Ah, yes that would break things. It should have been called I think it's best to make it actually flush and that should fix things. Then we can just add a dev note that says that |
Seems to work? |
This is what I see, both on master and in the https://cloudup.com/cAdBE6KTvYU It updates both consistently when using the changes from |
OK, I've reproduced this. You need the selection to jump to the This is actually not being caused by not re-running selectors when async mode changes. Here is what happens:
#19205 only fixes this by introducing an extra update that should be unnecessary. The correct way to fix this is by using a stable-cache- |
Another issue is that when async mode changes, we flush the queue before running PR incoming. |
Fixed: #19286. |
I'm not sure if this is a bug but I noticed that
withSelect()
anduseSelect()
call events/hooks at different times.I have a block that shows the number of blocks. When I use
withSelect()
the number of blocks are updated immediately, but if I useuseSelect()
and delete a block with the mouse, then the update happens only after I click somewhere else in the post. See the two examples below:My
withSelect()
code(updates are immediately coming through)
My
useSelect()
code(delete a block with the mouse triggers no update, only after clicking somewhere else in the post)
Is this intended behavior or am I missing something?
The text was updated successfully, but these errors were encountered: