From de64d2a4c222d82a6e6728b2f8111e7fa2bcdc7c Mon Sep 17 00:00:00 2001 From: dpiercey Date: Tue, 1 Jul 2025 09:21:37 -0700 Subject: [PATCH] fix: improve scheduler to support marko 6 --- src/shared.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/shared.ts b/src/shared.ts index 97bf845..ea947b5 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -145,8 +145,17 @@ export type AsyncReturnValue< type Callback = (...args: unknown[]) => void; const tick = - // Re-implements the same scheduler Marko 4/5 is using internally. - typeof window === "object" && typeof window.postMessage === "function" + // Re-implements the same scheduler Marko 4/5/6 is using internally. + typeof requestAnimationFrame === "function" && + typeof MessageChannel === "function" + ? (cb: Callback) => { + requestAnimationFrame(() => { + const { port1, port2 } = new MessageChannel(); + port1.onmessage = cb; + port2.postMessage(1); + }); + } + : typeof window === "object" && typeof window.postMessage === "function" ? (() => { let queue: Callback[] = []; const id = `${Math.random()}`;