From 808aacdc522feeb11f74047e5bdaa5e58c49125a Mon Sep 17 00:00:00 2001 From: Cyprien P Date: Tue, 5 Jul 2022 16:31:10 +0200 Subject: [PATCH] (core) Fix CustomWidget nbrowser test Summary: - test/nbrowser/CustomFilter keeps randomly fail on my local dev - it failed with `Cannot read property of null (reading 'postMessage`)` at line below: `this._rpc.setSendMessage(msg => this._iframe?.contentWindow!.postMessage(msg, '*'));` - I understand it was trying to send message before even the iframe was properly mounted - telling rpc to wait for the other end to send ready() successfully differ send message until everything's mounted. Test Plan: - should not break anything and test/nbrowser/CustomFilter should stop failing Reviewers: jarek Reviewed By: jarek Subscribers: jarek Differential Revision: https://phab.getgrist.com/D3510 --- app/client/components/WidgetFrame.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/client/components/WidgetFrame.ts b/app/client/components/WidgetFrame.ts index 3b714f10..3eb9ad54 100644 --- a/app/client/components/WidgetFrame.ts +++ b/app/client/components/WidgetFrame.ts @@ -68,6 +68,9 @@ export class WidgetFrame extends DisposableWithEvents { // Build RPC object and connect it to iframe. this._rpc = new Rpc({}); + // queue until iframe's content emit ready() message + this._rpc.queueOutgoingUntilReadyMessage(); + // Register outgoing message handler. this._rpc.setSendMessage(msg => this._iframe?.contentWindow!.postMessage(msg, '*'));