Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#35866 closed defect (bug) (fixed)

Multiple refresh requests from Customizer preview cause Uncaught TypeError: this.targetWindow is not a function

Reported by: westonruter Owned by: westonruter
Priority: normal Milestone: 4.5
Component: Customize Version: 3.4
Severity: normal Keywords: has-patch
Cc: Focuses: javascript

Description

Add a button to the Customizer preview which sends two refresh messages back-to-back to the pane:

wp.customize.preview.send( 'refresh' );
wp.customize.preview.send( 'refresh' );

This will also trigger the error.

Uncaught TypeError: this.targetWindow is not a function

This error is occurring specifically in wp.customize.Messenger.prototype.receive() where it does

if ( ! this.targetWindow() )
        return;

The problem is that when a refresh message is received, the wp.customize.PreviewFrame.prototype.destroy() method will get called which does:

delete this.targetWindow;

And so for the second message received, the this.targetWindow variable will be undefined.

The simplest fix here is to just make sure that this.targetWindow is defined before checking its value.

This was found when testing #27355.

Note that this won't be relevant once the iframe is loaded with the natural URL (#30028).

Attachments (1)

35866.0.diff (501 bytes ) - added by westonruter 10 years ago.

Download all attachments as: .zip

Change History (3)

@westonruter
10 years ago

#1 @westonruter
10 years ago

  • Keywords has-patch added
  • Owner set to westonruter
  • Status newaccepted

#2 @westonruter
10 years ago

  • Resolutionfixed
  • Status acceptedclosed

In 36583:

Customize: Prevent consecutive refresh requests from preview from causing JS error.

Fixes "Uncaught TypeError: this.targetWindow is not a function".

See #27355.
Fixes #35866.

Note: See TracTickets for help on using tickets.