appsmithorg/appsmith · error · Error

contextObj should be an object

Error message

contextObj should be an object

What it means

Thrown by the else-if branch of window.appsmith.triggerEvent() in the WDS Custom Widget iframe. After the string eventName check passes, an optional contextObj is validated: if it is truthy but not an object, the call is rejected because it is serialized into the CUSTOM_WIDGET_TRIGGER_EVENT payload. null and undefined are allowed (skipped by the truthy check).

Source

Thrown at app/client/src/widgets/wds/WDSCustomWidget/component/customWidgetscript.js:254

        },
        updateModel: (obj) => {
          if (!obj || typeof obj !== "object") {
            throw new Error("updateModel expects an object as parameter");
          }

          appsmith.model = Object.assign(
            Object.assign({}, appsmith.model),
            obj,
          );

          // Send an update model message to the parent
          channel.postMessage(EVENTS.CUSTOM_WIDGET_UPDATE_MODEL, obj);
        },
        triggerEvent: (eventName, contextObj) => {
          if (typeof eventName !== "string") {
            throw new Error("eventName should be a string");
          } else if (contextObj && typeof contextObj !== "object") {
            throw new Error("contextObj should be an object");
          }

          // Send a trigger event message to the parent
          channel.postMessage(EVENTS.CUSTOM_WIDGET_TRIGGER_EVENT, {
            eventName,
            contextObj,
          });
        },
        model: {},
        onReady: (fn) => {
          if (typeof fn !== "function") {
            throw new Error("onReady expects a function as parameter");
          }

          onReady = fn;

          if (isReady && !isReadyCalled && onReady) {
            onReady();

View on GitHub (pinned to 8cd9021c24)

Solutions

  1. Wrap context in an object: appsmith.triggerEvent('select', { id: rowId }).
  2. Omit the argument entirely when there is no context: appsmith.triggerEvent('ready').
  3. Pass null explicitly to signal no context: appsmith.triggerEvent('blur', null).

Example fix

// before
appsmith.triggerEvent('select', selectedId); // primitive number/string

// after
appsmith.triggerEvent('select', { id: selectedId });
Defensive patterns

Strategy: validation

Validate before calling

const ctx = contextObj == null ? undefined : contextObj;
if (ctx !== undefined && (typeof ctx !== 'object' || ctx === null)) {
  throw new TypeError('triggerEvent contextObj must be an object');
}
appsmith.triggerEvent(eventName, ctx);

Type guard

const isContextObject = (v) =>
  v == null || (typeof v === 'object' && !Array.isArray(v));

// usage
if (isContextObject(detail)) appsmith.triggerEvent(name, detail);

Try / catch

try {
  appsmith.triggerEvent(name, detail ? { value: detail } : undefined);
} catch (e) {
  console.error('triggerEvent rejected context:', e.message);
}

Prevention

When it happens

Trigger: Calling appsmith.triggerEvent('select', 'row-1'), appsmith.triggerEvent('select', 7), or appsmith.triggerEvent('select', Symbol()) in the WDS widget.

Common situations: Passing a primitive value directly instead of an event-detail object; forwarding a DOM target value rather than a wrapped detail.

Related errors


AI-assisted analysis of appsmithorg/appsmith@8cd9021c24 (2026-08-12). Data as JSON: /api/errors/d40702c4bba2c15f. Report an issue: GitHub.