-
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
Interactivity API: Prevent each directive errors and allow any iterable #67798
base: trunk
Are you sure you want to change the base?
Conversation
Flaky tests detected in 2470f6b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12260682362
|
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.83 MB
ℹ️ View Unchanged
|
What?
If an each directive does has a value without properties or without a callable
.map
method, it causes an error.Fixes #67174.
To do:
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