Theme Customizer: Fix race condition in previewer and use message channels
|Reported by:||koopersmith||Owned by:||koopersmith|
|Component:||Appearance||Keywords:||has-patch needs-testing commit|
In the customizer, if any settings are updated via JS (postMessage or otherwise) after a request is sent, the request becomes immediately outdated. This creates a race condition between the request and any JS-specific changes applied after the request is sent. To solve this problem, we should send the updated values to the preview frame once it renders.
This, however, requires several other things. First, it requires the preview frame to send a ready event to the parent once it has rendered. Second, it requires us to be able to distinguish messages across the same connection but sent to different windows. To control this, we can add a channel parameter to the Messenger object.
In general, this also has the beneficial side effect of making preview requests more robust.