WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#42414 closed defect (bug) (fixed)

Customize: Call to history.replaceState() before DOM ready in customizer preview causes error

Reported by: westonruter Owned by: westonruter
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.9
Component: Customize Keywords: has-patch commit dev-reviewed
Focuses: Cc:

Description (last modified by westonruter)

In 4.9 the injectUrlWithState() function was amended in [41597] with a dependency on a wp.customize.api.settings.changeset.autosave global. However, injectUrlWithState can be called prior to DOM ready when that global is populated, and the result is an undefined error. This can be seen in the Picard theme which does history.replaceState() before the Customizer preview is able to initialize itself. So this dependency on the global needs to be removed.

Attachments (1)

42414.0.diff (595 bytes) - added by westonruter 4 years ago.

Download all attachments as: .zip

Change History (10)

@westonruter
4 years ago

#1 @westonruter
4 years ago

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

The fix is trivial since the autosave flag is already determined via the presence of a customize_autosaved query param. Since we're parsing the initial query params already, we just have to re-use them. See 42414.0.diff.

This ticket was mentioned in Slack in #core-committers by westonruter. View the logs.


4 years ago

#3 @westonruter
4 years ago

  • Description modified (diff)

#4 @westonruter
4 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


4 years ago

#6 @obenland
4 years ago

  • Keywords dev-reviewed added; dev-feedback removed

I just spent an unreasonably long time trying to setup Picard and reproduce the bug you encountered. And failed.
Patch looks reasonable.

#7 @westonruter
4 years ago

@obenland oh, I should have noted that I had hacked Picard to get it to load. Theme needs to be updated for WP-API 2.0.

#8 @obenland
4 years ago

Ah yes. That's exactly what gave me grief

#9 @westonruter
4 years ago

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

In 42108:

Customize: Prevent history.replaceState() and history.pushState() calls from causing error in customize preview before DOM ready.

Amends [41597].
See #39896.
Fixes #42414.

Note: See TracTickets for help on using tickets.