diff --git a/.changeset/evil-steaks-grab.md b/.changeset/evil-steaks-grab.md new file mode 100644 index 000000000..c6b795213 --- /dev/null +++ b/.changeset/evil-steaks-grab.md @@ -0,0 +1,5 @@ +--- +"@marko/runtime-tags": patch +--- + +Refactor resume runtime to avoid executing other render and effect code in the queue when resuming. diff --git a/.sizes.json b/.sizes.json index 0e26ec643..eac3cc0fa 100644 --- a/.sizes.json +++ b/.sizes.json @@ -7,8 +7,8 @@ { "name": "*", "total": { - "min": 19635, - "brotli": 7527 + "min": 19644, + "brotli": 7530 } }, { @@ -33,12 +33,12 @@ "brotli": 89 }, "runtime": { - "min": 2134, - "brotli": 1119 + "min": 2139, + "brotli": 1123 }, "total": { - "min": 2230, - "brotli": 1208 + "min": 2235, + "brotli": 1212 } }, { @@ -63,12 +63,12 @@ "brotli": 116 }, "runtime": { - "min": 2286, - "brotli": 1162 + "min": 2291, + "brotli": 1164 }, "total": { - "min": 2416, - "brotli": 1278 + "min": 2421, + "brotli": 1280 } } ] diff --git a/.sizes/dom.js b/.sizes/dom.js index bf74c73d0..bce5e4205 100644 --- a/.sizes/dom.js +++ b/.sizes/dom.js @@ -1,4 +1,4 @@ -// size: 19635 (min) 7527 (brotli) +// size: 19644 (min) 7530 (brotli) var empty = [], rest = Symbol(); function attrTag(attrs) { @@ -323,15 +323,15 @@ function init(runtimeId = "M") { : visitText.length, )); return ( - (render.w = () => { + (render.w = (effects = []) => { try { (walk2(), (isResuming = 1)); for (let serialized of (resumes = render.r || [])) if ("string" == typeof serialized) lastEffect = serialized; else if ("number" == typeof serialized) - queueEffect( - (scopeLookup[serialized] ||= { L: serialized }), + effects.push( registeredValues[lastEffect], + (scopeLookup[serialized] ||= { L: serialized }), ); else for (let scope of serialized(serializeContext)) @@ -356,7 +356,7 @@ function init(runtimeId = "M") { node )((visitScope[lastToken] = visit.previousSibling))) : branchesEnabled && visitBranches()); - run(); + runEffects(effects); } finally { isResuming = visits.length = resumes.length = 0; } diff --git a/packages/runtime-tags/src/dom/resume.ts b/packages/runtime-tags/src/dom/resume.ts index 1fcae01ad..5ec1da63c 100644 --- a/packages/runtime-tags/src/dom/resume.ts +++ b/packages/runtime-tags/src/dom/resume.ts @@ -9,7 +9,7 @@ import { ResumeSymbol, type Scope, } from "../common/types"; -import { queueEffect, run } from "./queue"; +import { runEffects } from "./queue"; import type { Signal } from "./signals"; import { getDebugKey } from "./walker"; @@ -192,7 +192,7 @@ export function init(runtimeId = DEFAULT_RUNTIME_ID) { : visitText.length, )); - render.w = () => { + render.w = (effects: unknown[] = []) => { try { walk(); isResuming = 1; @@ -201,11 +201,11 @@ export function init(runtimeId = DEFAULT_RUNTIME_ID) { if (typeof serialized === "string") { lastEffect = serialized; } else if (typeof serialized === "number") { - queueEffect( + effects.push( + registeredValues[lastEffect!], (scopeLookup[serialized] ||= { [AccessorProp.Id]: serialized, } as Scope), - registeredValues[lastEffect!] as any, ); } else { for (const scope of serialized(serializeContext)) { @@ -249,7 +249,7 @@ export function init(runtimeId = DEFAULT_RUNTIME_ID) { } } - run(); + runEffects(effects); } finally { isResuming = visits.length = resumes.length = 0; }