-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Interactivity API: Prevent each directive errors and allow any iterable #67798
Conversation
Flaky tests detected in c04e29b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12355926558
|
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. |
eachIterator: { | ||
[ Symbol.iterator ]() { | ||
const vals = [ 'implements', 'iterator' ]; | ||
let i = 0; | ||
return { | ||
next() { | ||
return i < vals.length | ||
? { value: vals[ i++ ], done: false } | ||
: { done: true }; | ||
}, | ||
}; | ||
}, | ||
}, |
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'll admit, this is a bit esoteric, but it doesn't work in the iAPI but it seems like it could. I suspect its iterator is lost in the proxies.
Size Change: +56 B (0%) Total Size: 1.84 MB
ℹ️ View Unchanged
|
// TODO: Is there a problem with proxies here? | ||
// [ 'each-with-iterator', [ 'implements', 'iterator' ] ], |
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.
Is it still the case that there is a problem with proxies? I see that tests are passing in the CI.
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.
Oh, I realized you meant there's a problem only for the each-with-iterator
case which is commented out.
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.
That's right, it's commented out because it would not pass.
I didn't spend much time debugging the problem so I'm not sure what the issue is. It's some thing that apparently should work but does not, I'm not sure of the cause and don't really plan to spend time debugging it, maybe @DAreRodz know if this would create issues with store proxies.
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 looks good to me! 👍
We can create an issue for each-with-iterator
and merge this as it improves on the status quo.
ba4391a
to
c04e29b
Compare
…bles (WordPress#67798) Fix an issue where the each directive would error when a non-iterable value is received. Support more iterable values in the each directive. --- Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: michalczaplinski <czapla@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
…bles (WordPress#67798) Fix an issue where the each directive would error when a non-iterable value is received. Support more iterable values in the each directive. --- Co-authored-by: sirreal <jonsurrell@git.wordpress.org> Co-authored-by: michalczaplinski <czapla@git.wordpress.org> Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
What?
If an each directive does has a value without properties or without a callable
.map
method, it causes an error.Fixes #67174.
Why?
The API can be more robust in handling data problems like this. It's likely the each should render nothing if instead of
[]
the value isnull
or some other non-iterable.Take and example like this:
This has many opportunities for runtime errors, starting with the
null
initial value.How?
Check whether a property is iterable and iterate instead of calling its
.map
method.Testing Instructions
The snippets above can be used.
Needs unit tests.
Screenshots or screencast
demo.mov