Skip to content

Commit

Permalink
fix: ensure iframe is fully bootstrapped before attempting render (#2051
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fwouts authored Sep 27, 2023
1 parent a95c405 commit a1fe9a1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions iframe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare global {
// Exposed on the iframe.
__PREVIEWJS_IFRAME__: {
reportEvent(event: PreviewEvent): void;
render(options: RenderOptions): Promise<void>;
render?(options: RenderOptions): Promise<void>;
};
// Typically exposed on the iframe's parent to track its state.
__PREVIEWJS_CONTROLLER__: {
Expand Down Expand Up @@ -59,7 +59,16 @@ class PreviewIframeControllerImpl implements PreviewIframeController {
return;
}
const iframeWindow = this.options.getIframe()?.contentWindow;
if (!iframeWindow) {
if (!iframeWindow || this.bootstrapStatus !== "success") {
return;
}
if (!iframeWindow.__PREVIEWJS_IFRAME__.render) {
iframeWindow.__PREVIEWJS_IFRAME__.reportEvent({
kind: "error",
source: "renderer",
message:
"Iframe was bootstrapped but not fully initialised.\n\nPlease report this at https://github.com/fwouts/previewjs.",
});
return;
}
const renderPromise = iframeWindow.__PREVIEWJS_IFRAME__.render(options);
Expand Down

0 comments on commit a1fe9a1

Please sign in to comment.