Skip to content

feat: add queueMessages option to waitForReady#46

Merged
avigoldman merged 6 commits intomainfrom
framecast-auto-queue
Mar 30, 2026
Merged

feat: add queueMessages option to waitForReady#46
avigoldman merged 6 commits intomainfrom
framecast-auto-queue

Conversation

@avigoldman
Copy link
Copy Markdown
Contributor

What

Adds a queueMessages option to waitForReady(). When enabled, broadcast() calls made while waiting for the handshake are automatically queued and flushed once the other side signals readiness.

Why

Without this, consumers need to build their own message queuing logic to avoid losing messages during iframe initialization. With queueMessages: true, the consumer just calls waitForReady() and then broadcast() freely — framecast handles the rest.

API

// Parent side
const fc = new Framecast(iframe.contentWindow, { channel: 'my-channel' });
fc.waitForReady({ queueMessages: true }); // fire-and-forget

fc.broadcast(msg1); // queued
fc.broadcast(msg2); // queued
// iframe signals ready → both messages flushed automatically
fc.broadcast(msg3); // sent directly (no more queuing)
// Iframe side
const fc = new Framecast(window.parent, { channel: 'my-channel' });
fc.on('broadcast', handler);
fc.signalReady();

Testing

4 new tests covering: queue + flush on ready, flush on timeout (best-effort), no queuing after ready, opt-out with queueMessages: false.

Follows up on #44 (signalReady/waitForReady). Related: CON-6607

When waitForReady({ queueMessages: true }) is called, broadcast()
queues messages instead of sending them. Once the handshake completes
(or times out), the queue is flushed automatically.

This lets consumers call waitForReady() once and then broadcast()
freely without worrying about message loss during iframe
initialization — no external queuing logic needed.
- On timeout, queued messages are NOT flushed (iframe isn't ready,
  they'd be lost anyway). Consumer catches the rejection and decides.
- Add public clearQueue() for teardown scenarios (e.g. unmounting
  during the handshake window).
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 30, 2026

🦋 Changeset detected

Latest commit: 3fd0c4d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@ciolabs/framecast Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Separate onReady (flush) and onTimeout (discard) into distinct
paths instead of a shared cleanup(boolean). Inline the flush
logic so the flow is readable top-to-bottom.
@avigoldman avigoldman merged commit aabf68d into main Mar 30, 2026
1 check passed
@avigoldman avigoldman deleted the framecast-auto-queue branch March 30, 2026 14:31
@github-actions github-actions bot mentioned this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants