Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-peas-make.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/core": patch
---

Make registeredSteps a global singleton to protect against module duplication and caching issues
17 changes: 14 additions & 3 deletions packages/core/src/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ export type StepFunction<
stepId?: string;
};

const registeredSteps = new Map<string, StepFunction>();
const BUILTIN_RESPONSE_STEP_NAMES = new Set([
const RegisteredStepsKey = Symbol.for('@workflow/core//registeredSteps');

const globalSymbols: typeof globalThis & {
[RegisteredStepsKey]?: Map<string, StepFunction>;
} = 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',
Expand Down Expand Up @@ -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;
}

Expand Down
Loading