fix: isolate resume effects execution

This commit is contained in:
dpiercey 2025-11-12 09:34:10 -07:00 committed by Dylan Piercey
parent f79163dc0e
commit 3fbead1b58
4 changed files with 25 additions and 20 deletions

View File

@ -0,0 +1,5 @@
---
"@marko/runtime-tags": patch
---
Refactor resume runtime to avoid executing other render and effect code in the queue when resuming.

View File

@ -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
}
}
]

View File

@ -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;
}

View File

@ -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;
}