Skip to content

Commit 95a1674

Browse files
authored
Check initializedUpTo to make sure it's not pointing past a reverted result. (#1790)
- If we revert a result cell (or get some other server driven change), our closure captured initializedUpTo state will be out of sync. If this means it points after the last element, re-initialize the missing elements.
1 parent 9f5c577 commit 95a1674

File tree

1 file changed

+6
-1
lines changed
  • packages/runner/src/builtins

1 file changed

+6
-1
lines changed

packages/runner/src/builtins/map.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export function map(
7676

7777
// .getRaw() because we want the recipe itself and avoid following the
7878
// aliases in the recipe
79-
const opRecipe = op.getRaw() as any;
79+
const opRecipe = op.getRaw();
8080

8181
// If the result's value is undefined, set it to the empty array.
8282
if (resultWithLog.get() === undefined) {
@@ -98,6 +98,11 @@ export function map(
9898
}
9999

100100
const newArrayValue = resultWithLog.get().slice(0, initializedUpTo);
101+
// If we rollback a change to result cell, and that causes it to be
102+
// shorter, we need to re-initialize some cells.
103+
if (initializedUpTo > newArrayValue.length) {
104+
initializedUpTo = newArrayValue.length;
105+
}
101106
// Add values that have been appended
102107
while (initializedUpTo < list.length) {
103108
const resultCell = runtime.getCell(

0 commit comments

Comments
 (0)