diff --git a/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/ScriptInstruction.tsx b/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/ScriptInstruction.tsx index 1f145fe6257..41ec6a9fb1b 100644 --- a/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/ScriptInstruction.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/ScriptInstruction.tsx @@ -14,6 +14,11 @@ import { ValueBlock } from '@nocobase/plugin-workflow/client'; import { lang } from '../locale'; export default class extends V2ScriptInstruction { + constructor() { + super(); + this.bindTranslate(lang); + } + useInitializers(node: { id: string | number; title?: string }): SchemaInitializerItemType { return { name: node.title ?? `#${node.id}`, diff --git a/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/__tests__/scriptCompatibility.test.ts b/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/__tests__/scriptCompatibility.test.ts index b47782533e0..a6ba15e69ae 100644 --- a/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/__tests__/scriptCompatibility.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/__tests__/scriptCompatibility.test.ts @@ -9,6 +9,7 @@ import { describe, expect, it } from 'vitest'; +import { PluginWorkflowScriptClient } from '../'; import V1ScriptInstruction from '../ScriptInstruction'; import { lang } from '../../locale'; import V2ScriptInstruction from '../../client-v2/nodes/script'; @@ -34,4 +35,29 @@ describe('ScriptInstruction compatibility', () => { resultTitle: lang('Script result'), }); }); + + it('registers the v1 instruction as a class to avoid cross-entry instanceof checks', async () => { + const calls: unknown[][] = []; + const plugin = Object.create(PluginWorkflowScriptClient.prototype) as PluginWorkflowScriptClient & { + app: { + pm: { + get: () => { + registerInstruction: (...args: unknown[]) => number; + }; + }; + }; + }; + + plugin.app = { + pm: { + get: () => ({ + registerInstruction: (...args: unknown[]) => calls.push(args), + }), + }, + }; + + await plugin.load(); + + expect(calls).toEqual([['script', V1ScriptInstruction]]); + }); }); diff --git a/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/index.tsx b/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/index.tsx index 492bad97294..9ffaea89ae7 100644 --- a/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/index.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-javascript/src/client/index.tsx @@ -16,7 +16,7 @@ import { lang } from '../locale'; export class PluginWorkflowScriptClient extends Plugin { async load() { const workflow = this.app.pm.get('workflow') as WorkflowPlugin; - workflow.registerInstruction('script', new ScriptInstruction().bindTranslate(lang)); + workflow.registerInstruction('script', ScriptInstruction); } }