Skip to content

[Bug] Maps and Sets are polluted with _constructor-name_ property #104

@justinfagnani

Description

@justinfagnani

Describe the bug

In Storybook, any story arguments that are or contain Maps, Sets, and possibly instances of other classes, have a spurious _constructor-name_ property added to them.

This can interfere with code that's dealing with properties of object generically.

Steps to reproduce the behavior

  1. Make a component that displays Object.getOwnPropertyKeys() of an argument
  2. Use the component in a story with a Map as the argument
  3. See _constructor-name_ show up even though neither the story code nor the component added it.

The culprit appears to be here:

Object.assign(converted, { '_constructor-name_': value.constructor.name });

Expected behavior

Serialized objects are not mutated. Deserialized objects don't have extra properties.

A serialization library should not be modifying the objects sent tone serialized. If these are deserialized objects, then special JSON properties should be excluded from the serialization.

Screenshots and/or logs

Here's a screen shot of an object-inspector widget I'm building that's showing these extra properties inside Storybook:

Screenshot 2024-08-26 at 11 01 21 AM

Environment

Not an environment-specific issue.

Additional context

This bug has been reported multiple times on Storybook:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions