Launch: cleaner way of redirecting the Calypso window from within the block editor #47762
Labels
Focused Launch
Issues and PRs related to Focused Launch
[Pri] Normal
[Status] Blocked / Hold
[Type] Enhancement
Projects
The Focused Launch flow, included in the
@automattic/launch
package, needs to be imported both directly into Calypso and in the iframed block editor.The
LaunchContext
is used to abstract some of the differences that those different environments have. One of the properties available on theLaunchContext
is theredirectTo
function.When invoked from within the context of the
iframe
, at the moment theredirectTo
function specified by Editing Toolkit is a bit hacky, as it useswindow.top.location
and hardcodes thehttps://wordpress.com
origin.We should rewrite this functionality in a cleaner way, which would also allow us to avoid hardcoding the origin.
This is one way of implementing these changes:
@wordpress/hooks
library) inapps/wpcom-block-editor/src/calypso/features/iframe-bridge-server.js
. The hook callback would use theMessageChannel
APIs to communicate to theiframe
's parent windowclient/gutenberg/editor/calypsoify-iframe.tsx
, we should listen for this newly definedMessageChannel
action. In the callback, we should be able towindow.location.href = path
(no need to accesswindow.top
or to specify the origin)redirectTo
function defined inapps/editing-toolkit/editing-toolkit-plugin/editor-site-launch/src/attach-focused-launch.tsx
, instead of imperatively changing thewindow.top.location
, we should invoke the newly defined hook, if available (in wp-admin context, there is no iframe; see Focused launch: try enabling the flow in wp-admin #47803 and Focused Launch: more robust redirection when rendered within Editing Toolkit #47542 (comment))The text was updated successfully, but these errors were encountered: