Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#41231 closed defect (bug) (fixed)

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

Reported by: blackbam's profile Blackbam Owned by: joemcgill's profile 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 7 years ago.
41231.2.patch (1.8 KB) - added by joemcgill 7 years ago.

Download all attachments as: .zip

Change History (10)

#1 @Blackbam
7 years ago

  • Severity changed from normal to major

#2 @joemcgill
7 years 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
7 years ago

  • Keywords good-first-bug added

@yahil
7 years ago

#4 @yahil
7 years ago

  • Keywords has-patch added; needs-patch removed

#5 @joemcgill
7 years ago

  • Status changed from assigned to reviewing

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

@joemcgill
7 years ago

#6 @joemcgill
7 years 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
7 years 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
7 years 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.