-
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
Fix query loop with block bindings not working in the editor as expected #59283
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +5 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
I don't see those errors in the local environments I have. Did you run Could you share the console errors and the HTML of the blocks you're using? |
@SantosGuillamot I just did an Here are the console errors: Here is the code in question: And here is the block markup:
I created the query loop on a page as instructed in the description. |
My guess is that, as you are using ACF, the fields are not shown in the REST API in the If I am not mistaken, to make the ACF available through the |
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.
Everything works correctly on my end. I could reproduce the error that @artemiomorales reported.
Block.bindings.fix.mov
Code changes look good. As explained in the description, the issue was that whenever a core/block-editor
store gets re-created in the registry to support one of the nested blocks, it would lose the information about all the registered block binding sources. My proposal was to move it to the core/blocks
store to account for that. The other rationale I had is that it also better fits the @wordpress/blocks
package, as on the server both concepts are interconnected. The registered block binding sources can inject additional useContext
entries to supported block types.
Looking at the code lines reported on Browser Console, I suspect that the error that @artemiomorales sees is related to the fact the React hook is executed conditionally (it is guarded by two levels of checks) in these lines which breaks the rules of hooks: gutenberg/packages/block-editor/src/hooks/use-bindings-attributes.js Lines 42 to 54 in 599f336
That's a separate issue and should be fixed as well in a different PR. |
Thanks for taking a look!
If that's the issue, it should be fixed in the hook refactoring done in this pull pequest were the conditionals problem is solved. It'd be great if you can test if it is solved in that branch once it is rebased with these changes. |
…ted (#59283) * Move actions and selectors to blocks package * Update use bindings attributes hook to use blocksStore * Update blocks using getBlockBindingsSource * Update register sources dependency Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: artemiomorales <artemiosans@git.wordpress.org>
I just cherry-picked this PR to the cherry-pick-wp-6-5-beta-3 branch to get it included in the next release: 0086001 |
…ted (#59283) * Move actions and selectors to blocks package * Update use bindings attributes hook to use blocksStore * Update blocks using getBlockBindingsSource * Update register sources dependency Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: artemiomorales <artemiosans@git.wordpress.org>
What?
As reported here, the Query Loop shows the same value when the blocks are connected to custom fields. It should show each post custom field instead.
This is a first step to solve the issue, it will fully fixed after this refactoring of the block editor hook. This PR solves it for blocks like heading or paragraph but the issue still persists in images. That is a different there are two technical issues, one solved by this PR, and the other one solved in the linked one.
Why?
The current UX is confusing and block bindings feel broken.
How?
After triaging it with @gziolo , it seems that the
useSelect
used in the bindings hook doesn't have the registered sources when it is used in a post template preview.This is caused because:
It seems that the best option to solve this problem is to move the actions and selectors used by the block bindings to the
blocks
packages instead of theblock-editor
.Testing Instructions