WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 4 months ago

Last modified 4 months ago

#41231 closed defect (bug) (fixed)

media-views.js: Cannot read .length of undefined (this.controller.$uploaderToggler.length)

Reported by: Blackbam Owned by: joemcgill
Milestone: 4.8.1 Priority: normal
Severity: major Version: 4.8
Component: Media Keywords: good-first-bug has-patch
Focuses: accessibility, javascript, administration Cc:

Description

Some change in media-views.js destroyed all my custom scripts regarding media libraries when updating WordPress to the most recent version. I do not know what $uploaderToggler is however if it is not defined the script should not stop execution.

media-views.js lines 8228 - 8242 - currently:

	show: function() {
		this.$el.removeClass( 'hidden' );
		if ( this.controller.$uploaderToggler.length ) {
			this.controller.$uploaderToggler.attr( 'aria-expanded', 'true' );
		}
	},
	hide: function() {
		this.$el.addClass( 'hidden' );
		if ( this.controller.$uploaderToggler.length ) {
			this.controller.$uploaderToggler
				.attr( 'aria-expanded', 'false' )
				// Move focus back to the toggle button when closing the uploader.
				.focus();
		}
	}


How to fix:

	show: function() {
		this.$el.removeClass( 'hidden' );
		if ( this.controller.$uploaderToggler && this.controller.$uploaderToggler.length ) {
			this.controller.$uploaderToggler.attr( 'aria-expanded', 'true' );
		}
	},
	hide: function() {
		this.$el.addClass( 'hidden' );
		if ( this.controller.$uploaderToggler && this.controller.$uploaderToggler.length ) {
			this.controller.$uploaderToggler
				.attr( 'aria-expanded', 'false' )
				// Move focus back to the toggle button when closing the uploader.
				.focus();
		}
	}


Please repair this in future versions.

Attachments (2)

41231.patch (867 bytes) - added by yahil 4 months ago.
41231.2.patch (1.8 KB) - added by joemcgill 4 months ago.

Download all attachments as: .zip

Change History (10)

#1 @Blackbam
4 months ago

  • Severity changed from normal to major

#2 @joemcgill
4 months ago

  • Focuses accessibility added
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 4.8.1
  • Owner set to joemcgill
  • Status changed from new to assigned

Thanks @Blackbam,

Looks like this was added in [40359].

#3 @adamsilverstein
4 months ago

  • Keywords good-first-bug added

@yahil
4 months ago

#4 @yahil
4 months ago

  • Keywords has-patch added; needs-patch removed

#5 @joemcgill
4 months ago

  • Status changed from assigned to reviewing

Thanks @yahil. At first glance this patch looks exactly right.

@joemcgill
4 months ago

#6 @joemcgill
4 months ago

After looking more closely, this patch needed to be applied in src/wp-includes/js/media/views/uploader/inline.js since media-views.js gets autogenerated by Browserify.

41231.2.patch applies the change to src/wp-includes/js/media/views/uploader/inline.js as well.

#7 @joemcgill
4 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 41009:

Sanity check $uploaderToggler in wp.media.view.UploaderInline.

This ensures $uploaderToggler exists before checking length so any views
extending or scripts accessing this view, won't encounter errors that stop execution.

Props Blackbam, yahil.
Fixes #41231.

#8 @joemcgill
4 months ago

In 41010:

Sanity check $uploaderToggler in wp.media.view.UploaderInline.

This ensures $uploaderToggler exists before checking length so any views
extending or scripts accessing this view, won't encounter errors that stop execution.

See #41231.

Merges [41009] to the 4.8 branch.

Note: See TracTickets for help on using tickets.