Skip to content

Commit

Permalink
fix: in/out of order await nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Feb 21, 2025
1 parent 136bb14 commit d08be40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-cherries-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"marko": patch
---

Fix issue with nesting out of order awaits inside of in order awaits.
5 changes: 4 additions & 1 deletion packages/runtime-class/src/core-tags/core/await/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module.exports = function awaitTag(input, out) {
clientReorderContext =
out.global.___clientReorderContext ||
(out.global.___clientReorderContext = {
handleAwait: undefined,
instances: [],
nextId: 0,
});
Expand Down Expand Up @@ -158,7 +159,9 @@ module.exports = function awaitTag(input, out) {
oldEmit.apply(asyncOut, arguments);
};

if (clientReorderContext.instances) {
if (clientReorderContext.handleAwait) {
clientReorderContext.handleAwait(awaitInfo);
} else {
clientReorderContext.instances.push(awaitInfo);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,13 @@ module.exports = function (input, out) {
}

awaitContext.instances.forEach(handleAwait);

out.on("await:clientReorder", function (awaitInfo) {
awaitContext.handleAwait = function (awaitInfo) {
remaining++;
handleAwait(awaitInfo);
});
};

// Now that we have a listener attached, we want to receive any additional
// out-of-sync instances via an event
delete awaitContext.instances;
// out-of-sync instances via the method
awaitContext.instances = undefined;
});
};

0 comments on commit d08be40

Please sign in to comment.