question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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());
    }

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
markdalgleishcommented, Jun 9, 2021

We’re experiencing this issue because we’re executing our render code in a Node VM, which means we actually have multiple Object globals in memory and the toString equality check fails. I managed to create a minimal reproduction: https://runkit.com/embed/3svylngmhh23

1reaction
dcousenscommented, Apr 14, 2021

@BrianAtIgloo could you verify if !arg.hasOwnProperty('toString') resolves your issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object - JavaScript - MDN Web Docs
Chrome Edge Object Full support. Chrome1. Toggle history Full support. Edge12. Toggle hi... Object() constructor Full support. Chrome1. Toggle history Full support. Edge12. Toggle hi... assign...
Read more >
9. Classes — Python 3.11.1 documentation
Creating a new class creates a new type of object, allowing new instances of that ... The namespace containing the built-in names is...
Read more >
Python - Classes and Instances (__init__, __call__, etc.)
The return value will be the newly created object. In Python, there is no explicit new operator like there is in c++ or...
Read more >
OpenAPI Specification - Version 2.0
Version 2.0 specification defines a set of files required to describe an API. These files can then be used by the Swagger-UI project...
Read more >
Object Class (System)
Returns a string that represents the current object. Applies to. Product, Versions .NET, Core 1.0, Core 1.1, Core 2.0, Core ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found