mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fixed portal previews flashing background (#1975)
refs https://github.com/TryGhost/Team/issues/701 requires Portal@1.4.2 or later - changed `<GhSiteIframe @invisibleUntilLoaded>` to accept a string in place of a `true/false` value - if a string is passed then we'll set up a message event listener than listens for a `postMessage` from the iframe with data that matches the supplied string - updated `<GhSiteIframe>` usage for portal previews to use `@invisibleUntilLoaded="portal-ready"` so they listen for a message event rather than displaying as soon as we get a load event
This commit is contained in:
parent
6f9cd593a7
commit
b8e6107c6a
4 changed files with 25 additions and 3 deletions
|
@ -3,6 +3,7 @@
|
||||||
src={{this.srcUrl}}
|
src={{this.srcUrl}}
|
||||||
frameborder="0"
|
frameborder="0"
|
||||||
allowtransparency="true"
|
allowtransparency="true"
|
||||||
|
{{did-insert this.attachMessageListener}}
|
||||||
{{did-update this.resetSrcAttribute @guid}}
|
{{did-update this.resetSrcAttribute @guid}}
|
||||||
{{on "load" this.onLoad}}
|
{{on "load" this.onLoad}}
|
||||||
...attributes
|
...attributes
|
||||||
|
|
|
@ -11,6 +11,9 @@ export default class GhSiteIframeComponent extends Component {
|
||||||
@tracked isInvisible = this.args.invisibleUntilLoaded;
|
@tracked isInvisible = this.args.invisibleUntilLoaded;
|
||||||
|
|
||||||
willDestroy() {
|
willDestroy() {
|
||||||
|
if (this.messageListener) {
|
||||||
|
window.removeEventListener('message', this.messageListener);
|
||||||
|
}
|
||||||
this.args.onDestroyed?.();
|
this.args.onDestroyed?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,12 +43,30 @@ export default class GhSiteIframeComponent extends Component {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
onLoad(event) {
|
onLoad(event) {
|
||||||
if (this.args.invisibleUntilLoaded) {
|
if (this.args.invisibleUntilLoaded && typeof this.args.invisibleUntilLoaded === 'boolean') {
|
||||||
this.makeVisible.perform();
|
this.makeVisible.perform();
|
||||||
}
|
}
|
||||||
this.args.onLoad?.(event);
|
this.args.onLoad?.(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
attachMessageListener() {
|
||||||
|
if (typeof this.args.invisibleUntilLoaded === 'string') {
|
||||||
|
this.messageListener = (event) => {
|
||||||
|
const srcURL = new URL(this.srcUrl);
|
||||||
|
const originURL = new URL(event.origin);
|
||||||
|
|
||||||
|
if (originURL.origin === srcURL.origin) {
|
||||||
|
if (event.data === this.args.invisibleUntilLoaded) {
|
||||||
|
this.makeVisible.perform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('message', this.messageListener, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@task
|
@task
|
||||||
*makeVisible() {
|
*makeVisible() {
|
||||||
// give any scripts a bit of time to render before making visible
|
// give any scripts a bit of time to render before making visible
|
||||||
|
|
|
@ -248,7 +248,7 @@
|
||||||
class="gh-portal-siteiframe"
|
class="gh-portal-siteiframe"
|
||||||
@src={{this.portalPreviewUrl}}
|
@src={{this.portalPreviewUrl}}
|
||||||
@guid={{this.portalPreviewGuid}}
|
@guid={{this.portalPreviewGuid}}
|
||||||
@invisibleUntilLoaded={{true}} />
|
@invisibleUntilLoaded="portal-ready" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
<GhSiteIframe
|
<GhSiteIframe
|
||||||
@src={{this.portalPreviewUrl}}
|
@src={{this.portalPreviewUrl}}
|
||||||
@guid={{this.portalPreviewGuid}}
|
@guid={{this.portalPreviewGuid}}
|
||||||
@invisibleUntilLoaded={{true}}
|
@invisibleUntilLoaded="portal-ready"
|
||||||
@onLoad={{this.portalPreviewLoaded}}
|
@onLoad={{this.portalPreviewLoaded}}
|
||||||
@onDestroyed={{this.portalPreviewDestroyed}} />
|
@onDestroyed={{this.portalPreviewDestroyed}} />
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
Loading…
Add table
Reference in a new issue