-
Notifications
You must be signed in to change notification settings - Fork 4.6k
iAPI: Fix nested data-wp-each directives using the same items key
#71870
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
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. |
|
I've added e3f3c8f to solve some race issues in the |
|
Size Change: -8 B (0%) Total Size: 1.95 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 311ce65. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17975859131
|
luisherranz
left a comment
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.
LGTM!
I just have a question, but it's to understand the problem you've encountered. You can merge if you want.
| const { __navigationCount } = state; | ||
| return isNaN( __navigationCount ) ? 0 : __navigationCount; | ||
| }, | ||
| __navigationCount: NaN, |
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.
Why do you need to initialize navigationCount to NaN and use a derived state?
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.
Yeah, that part is a bit weird, but there's a reason.
The updateNavigationCount callback below is subscribed to the iAPI router module's state.url prop to count successful navigations. Every time the url property changes, the callback increases the counter.
However, as the router module is loaded asynchronously, and url is not present in the initial state, the callback runs at the time the module loads, even though there was no navigation at all.
I just needed a way to identify that case, and I came up with that solution. 🙂
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.
Yeah, maybe state.url should always be serialized from the server.
What?
Fixes a bug that happens with nested
data-wp-eachelements that use the same key for the items they render. E.g., in the following HTML, there are two different lists that use the sameitemkey:The resulting HTML, once the directives are evaluated in the client, is this:
This happens because, instead of shadowing the inherited
itemprop from the parent, the child contexts are modifying the inheriteditemprop. In short, all children modify the same prop sequentially and inherit the same value.With the changes included in this PR, the final result is as expected.
Why?
This case should be supported. The server-side directive processing already generates the proper HTML.
How?
Instead of changing the property in the context with key
[itemProp]after defining the local context, which actually points to the inherited property of the parent context, the local context is instantiated with the[itemProp]property, effectively shadowing the parent one.Testing Instructions