-
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
Cannot bind attributes to direct children of data-wp-each
#60981
Comments
I can confirm the issue on my side as well. |
I wasn't able to debug this effectively. This was my minimal repro block: // render.php
<?php
$context = [
'items' => [
[
'id' => 1,
'title' => 'One',
'classes' => 'class1',
'is1' => true,
],
[
'id' => 2,
'title' => 'Two',
'classes' => 'class2',
'is2' => true,
],
],
];
?>
<template data-wp-each="context.items" data-wp-each-key="context.items.id">
<div data-wp-bind--class="context.item.classes">
<span data-wp-text="context.item.title"></span>
</div>
</template> I was able to establish that the context is being reset incorrectly somewhere around those lines: gutenberg/packages/interactivity/src/hooks.tsx Lines 358 to 368 in d36b40d
gutenberg/packages/interactivity/src/hooks.tsx Lines 288 to 291 in d36b40d
It seems that the directives are run twice and on the second run the |
I was going to try to fix this issue, but I can't reproduce it anymore. This is the code that I used: <!-- render.php -->
<?php
$context = [
'items' => [
[
'title' => 'One',
'classes' => 'class1',
],
[
'title' => 'Two',
'classes' => 'class2',
],
],
];
?>
<div
<?php echo wp_interactivity_data_wp_context( $context ); ?>
data-wp-interactive="repro/60981"
>
<style> .class1 { color: red; } .class2 { color: blue } </style>
<template data-wp-each="context.items" data-wp-each-key="context.item.id">
<div data-wp-bind--class="context.item.classes">
<span data-wp-text="context.item.title" data-wp-bind--id="context."></span>
<button data-wp-on--click="actions.inc" data-wp-text="state.count"> </button>
</div>
</template>
</div> // view.js
import { store, getContext } from "@wordpress/interactivity";
const { state } = store("repro/60981", {
state: {
count: 0,
},
actions: {
inc: () => {
state.count++;
},
},
}); Result: Screen.Recording.2024-07-11.at.16.54.57.mov@danielpost Please let me know if the problem still persist for you and share your reproduction if possible! Otherwise, I will close this issue as resolved, thanks! |
I'm going to close this issue as the problem cannot be reproduced anymore. Feel free to open a new one if it re-appears! |
Description
When binding an attribute using
data-wp-bind
to a direct child of adata-wp-each
loop, you get the following errors:It does seem to bind the attribute correctly, but any interactivity is broken.
Step-by-step reproduction instructions
Minimal example to reproduce the issue:
Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: