From 398a2d160ea9987931ace450f33aa5427695372f Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Tue, 9 Sep 2025 11:11:31 +0200 Subject: [PATCH] HOTFIX: Fix duplicate collectionSlug field error - Multiple step types (create-document, read-document, etc.) were defining collectionSlug fields - These created duplicate field names at the same level in the Workflow collection - Fixed by prefixing step field names with step slug (__step_{stepSlug}_{fieldName}) - Added virtual field hooks to store/retrieve data using original field names - Resolves DuplicateFieldName error preventing PayloadCMS initialization Fixes: #duplicate-field-name-issue Closes: User bug report for @xtr-dev/payload-automation@0.0.30 --- src/collections/Workflow.ts | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/collections/Workflow.ts b/src/collections/Workflow.ts index 226f1f5..ed9b692 100644 --- a/src/collections/Workflow.ts +++ b/src/collections/Workflow.ts @@ -319,17 +319,45 @@ export const createWorkflowCollection: (options: WorkflowsPlug } ] }, - ...(steps || []).flatMap(step => (step.inputSchema || []).map(field => ({ - ...field, - admin: { - ...(field.admin || {}), - condition: (...args) => args[1]?.step === step.slug && ( - field.admin?.condition ? - field.admin.condition.call(this, ...args) : - true - ), - }, - } as Field))), + ...(steps || []).flatMap(step => (step.inputSchema || []).map(field => { + const originalName = (field as any).name; + const resultField: any = { + ...field, + // Prefix field name with step slug to avoid conflicts + name: `__step_${step.slug}_${originalName}`, + admin: { + ...(field.admin || {}), + condition: (...args: any[]) => args[1]?.step === step.slug && ( + (field.admin as any)?.condition ? + (field.admin as any).condition.call(this, ...args) : + true + ), + }, + virtual: true, + }; + + // Add hooks to store/retrieve from the step's input data + resultField.hooks = { + ...((field as any).hooks || {}), + afterRead: [ + ...(((field as any).hooks)?.afterRead || []), + ({ siblingData }: any) => { + // Read from step input data using original field name + return siblingData?.[originalName] || (field as any).defaultValue; + } + ], + beforeChange: [ + ...(((field as any).hooks)?.beforeChange || []), + ({ siblingData, value }: any) => { + // Store in step data using original field name + siblingData[originalName] = value; + return undefined; // Don't store the prefixed field + } + ] + }; + + return resultField as Field; + })), { name: 'dependencies', type: 'text',