feat: break island render task into to multiple tasks (#1019)
Each island is now rendered in a separate task. This significantly reduces blocking time.
This commit is contained in:
@@ -26,7 +26,7 @@ function createRootFragment(
|
|||||||
|
|
||||||
// deno-lint-ignore no-explicit-any
|
// deno-lint-ignore no-explicit-any
|
||||||
export function revive(islands: Record<string, ComponentType>, props: any[]) {
|
export function revive(islands: Record<string, ComponentType>, props: any[]) {
|
||||||
function walk(node: Node | null) {
|
async function walk(node: Node | null) {
|
||||||
const tag = node!.nodeType === 8 &&
|
const tag = node!.nodeType === 8 &&
|
||||||
((node as Comment).data.match(/^\s*frsh-(.*)\s*$/) || [])[1];
|
((node as Comment).data.match(/^\s*frsh-(.*)\s*$/) || [])[1];
|
||||||
let endNode: Node | null = null;
|
let endNode: Node | null = null;
|
||||||
@@ -41,14 +41,19 @@ export function revive(islands: Record<string, ComponentType>, props: any[]) {
|
|||||||
startNode.parentNode!.removeChild(startNode); // remove start tag node
|
startNode.parentNode!.removeChild(startNode); // remove start tag node
|
||||||
|
|
||||||
const [id, n] = tag.split(":");
|
const [id, n] = tag.split(":");
|
||||||
render(
|
const _render = () => {
|
||||||
h(islands[id], props[Number(n)]),
|
render(
|
||||||
createRootFragment(
|
h(islands[id], props[Number(n)]),
|
||||||
parent! as HTMLElement,
|
createRootFragment(
|
||||||
children,
|
parent! as HTMLElement,
|
||||||
// deno-lint-ignore no-explicit-any
|
children,
|
||||||
) as any as HTMLElement,
|
// deno-lint-ignore no-explicit-any
|
||||||
);
|
) as any as HTMLElement,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
"scheduler" in window
|
||||||
|
? await scheduler!.postTask(_render)
|
||||||
|
: setTimeout(_render, 0);
|
||||||
endNode = node;
|
endNode = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user