diff --git a/.changeset/six-peas-make.md b/.changeset/six-peas-make.md new file mode 100644 index 0000000000..23f2fe2756 --- /dev/null +++ b/.changeset/six-peas-make.md @@ -0,0 +1,5 @@ +--- +"@workflow/core": patch +--- + +Make registeredSteps a global singleton to protect against module duplication and caching issues diff --git a/packages/core/src/private.ts b/packages/core/src/private.ts index 97b028b018..3ccaadd1e0 100644 --- a/packages/core/src/private.ts +++ b/packages/core/src/private.ts @@ -15,8 +15,19 @@ export type StepFunction< stepId?: string; }; -const registeredSteps = new Map(); -const BUILTIN_RESPONSE_STEP_NAMES = new Set([ +const RegisteredStepsKey = Symbol.for('@workflow/core//registeredSteps'); + +const globalSymbols: typeof globalThis & { + [RegisteredStepsKey]?: Map; +} = globalThis; + +// biome-ignore lint/suspicious/noAssignInExpressions: / +const registeredSteps = (globalSymbols[RegisteredStepsKey] ??= new Map< + string, + StepFunction +>()); + +const BUILTIN_STEP_NAMES = new Set([ '__builtin_response_array_buffer', '__builtin_response_json', '__builtin_response_text', @@ -59,7 +70,7 @@ function getStepIdAliasCandidates(stepId: string): string[] { } function getBuiltinResponseStepAlias(stepId: string): StepFunction | undefined { - if (!BUILTIN_RESPONSE_STEP_NAMES.has(stepId)) { + if (!BUILTIN_STEP_NAMES.has(stepId)) { return undefined; }