-
Notifications
You must be signed in to change notification settings - Fork 123
[Bug] Can't use structuredClone in workflow code #1663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've just found this too, trying to use structuredClone to copy some input arrays that are then modified inside a class. @mjameswh is there any reason not to expose this in the workflow sandbox same as we did for TextDecoder etc? I can open a PR to do that. |
diff --git a/node_modules/@temporalio/worker/lib/workflow/reusable-vm.js b/node_modules/@temporalio/worker/lib/workflow/reusable-vm.js
index f3a06d6..8fb90fd 100644
--- a/node_modules/@temporalio/worker/lib/workflow/reusable-vm.js
+++ b/node_modules/@temporalio/worker/lib/workflow/reusable-vm.js
@@ -60,6 +60,7 @@ class ReusableVMWorkflowCreator {
TextEncoder: node_util_1.TextEncoder,
TextDecoder: node_util_1.TextDecoder,
AbortController,
+ structuredClone,
};
this._context = node_vm_1.default.createContext(globals, { microtaskMode: 'afterEvaluate' });
this.injectConsole();
diff --git a/node_modules/@temporalio/worker/lib/workflow/vm.js b/node_modules/@temporalio/worker/lib/workflow/vm.js
index 239aa90..21e2655 100644
--- a/node_modules/@temporalio/worker/lib/workflow/vm.js
+++ b/node_modules/@temporalio/worker/lib/workflow/vm.js
@@ -69,6 +69,7 @@ class VMWorkflowCreator {
TextEncoder: node_util_1.TextEncoder,
TextDecoder: node_util_1.TextDecoder,
AbortController,
+ structuredClone,
};
const context = node_vm_1.default.createContext(globals, { microtaskMode: 'afterEvaluate' });
this.script.runInContext(context); If you use patch-package, this is a patch that will get this working. Testing myself in our system it all seems to work fine. |
This is a summary from this Slack conversation. If the For example (this was executed ):
We have a utility function that we use internally to recursively fix some well known prototypes on objects being transferred from an outer execution context. However, using that over For those reasons, the best approach at this time is to load a polyfill. |
Fascinating - didn't know that. I would say that's worth documenting since I think this will come up again a lot. Going to replace my patch with a poly-fill. |
Yeah, been thinking about this for some time. We definitely need to provide more clarity regarding what expectations hold inside the workflow sandbox and why some things are not provided. Our current claim about only exposing "APIs that are deterministic-safe" is too imprecise, and not sufficient since there are other constraints at play. |
What are you really trying to do?
Make a copy of value in workflow code with structuredClone() function of nodejs.
Describe the bug
It seems that webpack'ed code lack of structuredClone function.
Minimal Reproduction
// in workflow code
const someData = { foo: 'bar' }
const cloneData = structuredClone(someData);
Environment/Versions
The text was updated successfully, but these errors were encountered: