From 8bdb8e17dbc6d1c56a6cf97b04c9a3177b66fdd5 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Thu, 2 Apr 2026 09:45:14 -0700 Subject: [PATCH 1/2] docs: rename 'Complex Example' to 'Instance Methods as Steps' in serialization guide Rework the section title and introductory copy to better reflect the purpose: making classes with Node.js APIs / side effects workflow-compatible by adding "use step" to instance methods. --- docs/content/docs/foundations/serialization.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/content/docs/foundations/serialization.mdx b/docs/content/docs/foundations/serialization.mdx index b6338f37d5..6565d17a6b 100644 --- a/docs/content/docs/foundations/serialization.mdx +++ b/docs/content/docs/foundations/serialization.mdx @@ -205,9 +205,9 @@ The `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` methods run inside the workf Keep these methods simple and focused on data transformation only. -### Complex Example +### Instance Methods as Steps -A class that uses Node.js APIs or other non-deterministic operations cannot be used directly inside a workflow function. The recommended approach is to make the class workflow-compatible by adding `"use step"` to its instance methods. The SWC compiler will strip the method bodies from the workflow bundle and replace them with proxy functions that invoke the method as a step — with full Node.js runtime access. The `this` context (the class instance) is automatically serialized and deserialized across the workflow/step boundary. +In practice, many classes have methods that need Node.js APIs, perform network calls, or interact with databases — operations that are not allowed in the `"use workflow"` execution context. You can make these methods workflow-compatible by adding `"use step"` to them. The SWC compiler will strip the method bodies from the workflow bundle and replace them with proxy functions that invoke the method as a step — with full Node.js runtime access. The `this` context (the class instance) is automatically serialized and deserialized across the workflow/step boundary. This requires the class to implement `WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE`, so that the instance can be passed to the step execution context. From 2e72ae441cd5530b78a0507f15645f1d5b49a010 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Thu, 2 Apr 2026 09:51:37 -0700 Subject: [PATCH 2/2] docs: clarify that the static requirement applies to serialization hooks Make the callout explicitly name WORKFLOW_SERIALIZE and WORKFLOW_DESERIALIZE so it doesn't read as a blanket restriction on instance methods, which would contradict the 'Instance Methods as Steps' section below. --- docs/content/docs/foundations/serialization.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/docs/foundations/serialization.mdx b/docs/content/docs/foundations/serialization.mdx index 6565d17a6b..311d781c7c 100644 --- a/docs/content/docs/foundations/serialization.mdx +++ b/docs/content/docs/foundations/serialization.mdx @@ -190,7 +190,7 @@ async function doublePoint(point: Point) { ### Requirements -Both methods must be implemented as **static** methods on the class. Instance methods are not supported. +`WORKFLOW_SERIALIZE` and `WORKFLOW_DESERIALIZE` must be implemented as **static** methods on the class. Defining them as instance methods is not supported. - The data returned by `WORKFLOW_SERIALIZE` must itself be serializable (see [Supported Serializable Types](#supported-serializable-types))