From 273aa2ac5c0f2c7b6823e44961aa4bc4f12d0ced Mon Sep 17 00:00:00 2001 From: Igor Brasileiro Date: Wed, 7 Jun 2023 07:32:16 -0300 Subject: [PATCH] feat: break island render task into to multiple tasks (#1019) Each island is now rendered in a separate task. This significantly reduces blocking time. --- src/runtime/entrypoints/main.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts index 50e2c6bd..4e613479 100644 --- a/src/runtime/entrypoints/main.ts +++ b/src/runtime/entrypoints/main.ts @@ -26,7 +26,7 @@ function createRootFragment( // deno-lint-ignore no-explicit-any export function revive(islands: Record, props: any[]) { - function walk(node: Node | null) { + async function walk(node: Node | null) { const tag = node!.nodeType === 8 && ((node as Comment).data.match(/^\s*frsh-(.*)\s*$/) || [])[1]; let endNode: Node | null = null; @@ -41,14 +41,19 @@ export function revive(islands: Record, props: any[]) { startNode.parentNode!.removeChild(startNode); // remove start tag node const [id, n] = tag.split(":"); - render( - h(islands[id], props[Number(n)]), - createRootFragment( - parent! as HTMLElement, - children, - // deno-lint-ignore no-explicit-any - ) as any as HTMLElement, - ); + const _render = () => { + render( + h(islands[id], props[Number(n)]), + createRootFragment( + parent! as HTMLElement, + children, + // deno-lint-ignore no-explicit-any + ) as any as HTMLElement, + ); + }; + "scheduler" in window + ? await scheduler!.postTask(_render) + : setTimeout(_render, 0); endNode = node; }