WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 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
Milestone: 4.5 Priority: normal
Severity: normal Version: 3.4
Component: Customize Keywords: has-patch
Focuses: javascript Cc:
PR Number:

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 4 years ago.

Download all attachments as: .zip

Change History (3)

@westonruter
4 years ago

#1 @westonruter
4 years ago

  • Keywords has-patch added
  • Owner set to westonruter
  • Status changed from new to accepted

#2 @westonruter
4 years ago

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

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.