Skip to content

Class names being returned as [object Object] as of v2.3.0 #240

Description

@BrianAtIgloo

Hi, first off - thank you for maintaining this fantastic package!

That said, we've run into an issue with v2.3.0 where our bundled components are now outputting [object Object] class names because of this recent change to support a custom toString fn.

The problem only occurs after we run our code through our build pipeline which uses Rollup/Babel to produce a CJS bundle so we can render server-side.

Component Code:

  const inputStyleClass = classNames(styles['text_input__input'], {
    [styles['text_input__input--with-icon']]: !!icon,
  });

Transpiled code:

  var inputStyleClass = classnames(
    styles$z['text_input__input'],
    (_classNames2 = {},
        _defineProperty$2(_classNames2, styles$z['text_input__input--with-icon'], !!icon),
        _classNames2,
    )
  );

We've locked our components to 2.2.6 to resolve the issue and suggest the following change:

    if ((/\{\s*\[native code\]\s*\}/).test(arg.toString)) {
      for (var key in arg) {
        if (hasOwn.call(arg, key) && arg[key]) {
          classes.push(key);
        }
      }
    } else {
      classes.push(arg.toString());
    }

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions