Skip to content

Commit 51d39bc

Browse files
authored
feat(workflow): Clone sink args at call time (#1118)
Use [structuredClone](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) to clone sink call arguments at call time. While this adds some runtime overhead, it leads to a more predictable experience when an argument is mutated after being passed to a sink as well as better exceptions when passing a non-transferrable object to a sink. Only available from Node.js >= 17.
1 parent 14189f1 commit 51d39bc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

packages/workflow/src/workflow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ export function proxySinks<T extends Sinks>(): T {
895895
activator.sinkCalls.push({
896896
ifaceName: ifaceName as string,
897897
fnName: fnName as string,
898-
args,
898+
// Only available from node 17.
899+
args: (globalThis as any).structuredClone ? (globalThis as any).structuredClone(args) : args,
899900
});
900901
};
901902
},
@@ -1283,8 +1284,7 @@ export const log: LoggerSinks['defaultWorkerLogger'] = Object.fromEntries(
12831284
return loggerSinks.defaultWorkerLogger[level](message, {
12841285
// Inject the call time in nanosecond resolution as expected by the worker logger.
12851286
[LogTimestamp]: getActivator().getTimeOfDay(),
1286-
// Only available from node 17.
1287-
...((globalThis as any).structuredClone ? (globalThis as any).structuredClone(attrs) : attrs),
1287+
...attrs,
12881288
});
12891289
},
12901290
];

0 commit comments

Comments
 (0)