@@ -985,45 +985,46 @@ const generateOnInstanceWrapperFn = (
985985 componentRegistry: ComponentRegistry,
986986 customFn?: TriggerEventFunction,
987987): TriggerEventFunction | undefined => {
988- const onInstanceFn: TriggerEventFunction | undefined =
989- componentRef && typeof onTrigger !== "function"
990- ? async (context, params) => {
991- // @ts-expect-error: _components isn't part of the public API
992- const _components = context._components ?? {
993- invokeTrigger: () => {},
994- };
995- const invokeTrigger: TriggerActionInvokeFunction = _components.invokeTrigger;
996- const cniContext = createCNIContext(context, componentRegistry);
988+ const usesComponentRef = componentRef && typeof onTrigger !== "function";
997989
998- // Using runWithContext allows for component action invocation via manifest.
999- return await runWithContext(cniContext, async () => {
1000- const invokeResponse =
1001- (await invokeTrigger(
1002- invokeTriggerComponentInput(componentRef, onTrigger, eventName),
1003- cniContext,
1004- null,
1005- params,
1006- )) || {};
1007-
1008- let customResponse: TriggerEventFunctionReturn = {};
1009- if (customFn) {
1010- customResponse = (await customFn(cniContext, params)) || {};
1011- }
1012-
1013- return merge(invokeResponse, customResponse);
1014- });
990+ if (usesComponentRef) {
991+ return async (context, params) => {
992+ // @ts-expect-error: _components isn't part of the public API
993+ const _components = context._components ?? {
994+ invokeTrigger: () => {},
995+ };
996+ const invokeTrigger: TriggerActionInvokeFunction = _components.invokeTrigger;
997+ const cniContext = createCNIContext(context, componentRegistry);
998+
999+ // Using runWithContext allows for component action invocation via manifest.
1000+ return await runWithContext(cniContext, async () => {
1001+ const invokeResponse =
1002+ (await invokeTrigger(
1003+ invokeTriggerComponentInput(componentRef, onTrigger, eventName),
1004+ cniContext,
1005+ null,
1006+ params,
1007+ )) || {};
1008+
1009+ let customResponse: TriggerEventFunctionReturn = {};
1010+ if (customFn) {
1011+ customResponse = (await customFn(cniContext, params)) || {};
10151012 }
1016- : async (context, params) => {
1017- if (customFn) {
1018- const cniContext = createCNIContext(context, componentRegistry);
1019- // Using runWithContext allows for component action invocation via manifest.
1020- return await runWithContext(cniContext, async () => {
1021- return await customFn(cniContext, params);
1022- });
1023- }
1024- };
10251013
1026- return onInstanceFn;
1014+ return merge(invokeResponse, customResponse);
1015+ });
1016+ };
1017+ } else if (customFn) {
1018+ return async (context, params) => {
1019+ const cniContext = createCNIContext(context, componentRegistry);
1020+ // Using runWithContext allows for component action invocation via manifest.
1021+ return await runWithContext(cniContext, async () => {
1022+ return await customFn(cniContext, params);
1023+ });
1024+ };
1025+ } else {
1026+ return;
1027+ }
10271028};
10281029
10291030const convertOnExecution =
0 commit comments