appsmithorg/appsmith · error · Error

updateModel expects an object as parameter

Error message

updateModel expects an object as parameter

What it means

Thrown by window.appsmith.updateModel() in a legacy Custom Widget iframe. updateModel merges a partial object into appsmith.model via Object.assign and forwards the delta to the parent with a CUSTOM_WIDGET_UPDATE_MODEL message. The guard rejects null/undefined and any non-object primitive because Object.assign on a primitive would silently no-op or corrupt the model.

Source

Thrown at app/client/src/widgets/CustomWidget/component/customWidgetscript.js:259

          if (typeof fn !== "function") {
            throw new Error("onModelChange expects a function as parameter");
          }

          modelSubscribers.push(fn);
          fn(window.appsmith.model);

          return () => {
            // Unsubscribe from model changes
            const index = modelSubscribers.indexOf(fn);

            if (index > -1) {
              modelSubscribers.splice(index, 1);
            }
          };
        },
        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

View on GitHub (pinned to 8cd9021c24)

Solutions

  1. Always pass a plain object literal: appsmith.updateModel({ key: value }).
  2. Guard optional patches: if (patch) appsmith.updateModel(patch); or default to {} : appsmith.updateModel(patch ?? {}).
  3. Construct the patch in a typed local object before sending so it can never be a primitive.
  4. Avoid passing arrays; wrap list data under a key, e.g. updateModel({ items: [...] }).

Example fix

// before
appsmith.updateModel(selectedItem); // selectedItem may be null

// after
appsmith.updateModel({ selected: selectedItem });
Defensive patterns

Strategy: validation

Validate before calling

// Build the patch as a guaranteed object
const patch = maybePatch ?? {};
if (typeof patch !== 'object' || patch === null) {
  throw new TypeError('updateModel needs a plain object');
}
appsmith.updateModel(patch);

Type guard

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

// usage
if (isPlainObject(patch)) appsmith.updateModel(patch);

Try / catch

try {
  appsmith.updateModel(patch ?? {});
} catch (e) {
  console.error('updateModel rejected patch:', e.message);
}

Prevention

When it happens

Trigger: Calling appsmith.updateModel(null), appsmith.updateModel(undefined), appsmith.updateModel('foo'), appsmith.updateModel(42), or appsmith.updateModel() with no argument. Note typeof [] === 'object', so arrays are NOT rejected by this guard but will misbehave when merged.

Common situations: Conditionally building a patch object that ends up undefined when no field changed; passing a serialized string instead of an object; spreading a possibly-undefined variable (appsmith.updateModel(maybePatch)) without a default.

Related errors


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