Fix media modal crash on WP 7.0 due to attachment filters wrapper change#399
Fix media modal crash on WP 7.0 due to attachment filters wrapper change#399kraftbj wants to merge 3 commits into
Conversation
WP core commit [61757] wrapped the media attachment filters <select>
and <label> in a container <div> for accessibility. This changed
toolbar.get('filters') from returning the AttachmentFilters view
directly to returning a wrapper View, causing customizeFilters()
to crash with "Cannot read properties of undefined (reading 'all')".
Resolve the actual AttachmentFilters view by checking whether the
returned view has a .filters property, and if not, traversing its
subviews to find the AttachmentFilters instance. This is compatible
with both WP < 7.0 and WP 7.0+.
Fixes #396
See https://core.trac.wordpress.org/ticket/64948
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #399 +/- ##
============================================
- Coverage 54.00% 52.65% -1.35%
Complexity 4423 4423
============================================
Files 298 298
Lines 39467 39475 +8
============================================
- Hits 21314 20786 -528
- Misses 18153 18689 +536
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I was going to wait a bit longer for https://core.trac.wordpress.org/ticket/64948 to be potentially fixed before WP 7.0 is released 🤔 |
|
That's fine! I figure it's quick to merge and ship a quick compat release if we need to this way. |
cbravobernal
left a comment
There was a problem hiding this comment.
The approach looks right and is adaptive to both structures: on WP < 7.0 (and on a future core where toolbar.get( 'filters' ) returns the AttachmentFilters view directly again), the ! filtersView.filters check falls through and nothing changes; on WP 7.0 the wrapper's subviews are searched.
One edge worth hardening while we're here: if toolbar.get( 'filters' ) returns undefined, or no subview exposes .filters, filters remains the wrapper (or undefined) and the function still crashes a few lines later at filters.filters.all. A small guard after the lookup would make this bulletproof:
if ( ! filters || ! filters.filters ) {
return;
}With that, the media modal degrades gracefully (default filters, no SCF customization) instead of breaking if core moves the view again.
Review run via Claude Code, reviewed by @cbravobernal.
If toolbar.get('filters') returns undefined or no subview exposes a
.filters property (e.g. core moves the view again), bail early so the
media modal degrades to the default filters instead of crashing at
filters.filters.all.
WP core commit 61757 wrapped the media attachment filters
<select>and<label>in a container<div>for accessibility. This changedtoolbar.get('filters')from returning theAttachmentFiltersview directly to returning a wrapperwp.media.View, causingcustomizeFilters()to crash with:This broke the media modal for any SCF image/file field on WP 7.0.
The fix resolves the actual
AttachmentFiltersview by checking whether the returned view has a.filtersproperty. If not (WP 7.0+), it traverses the wrapper's subviews to find theAttachmentFiltersinstance. This is compatible with both WP < 7.0 and WP 7.0+.Tested on both WP 6.9.4 and WP 7.0-RC2 with the full E2E suite passing.
Fixes #396
See https://core.trac.wordpress.org/ticket/64948
Use of AI Tools
This PR was authored with assistance from Claude Code (Anthropic). The fix was developed after debugging the root cause using Playwright-based investigation of the media modal behavior on WP 7.0-RC2.