Skip to content

Multiple classes being mangled to "a" #11868

Open
ayishagisel/create-react-app
#119
@jashsayani

Description

@jashsayani

Describe the bug

I have a Base class called BaseModel, and multiple sub-classes like User, Foo, Bar, etc. They all extend BaseModel. The BaseModel class has some logic like:

static _instances = {};

constructor(initialData) {
    if (!BaseModel._instances[this.constructor.name]) {
      BaseModel._instances[this.constructor.name] = [];
    }
    BaseModel._instances[this.constructor.name].push(this);
}

This allows me to have a reference to all instances of the class. The problem is that deploying the app renames all sub-classes to "a" (instead of using "a", "b", etc. for different sub-classes). Hence, my _instances map has multiple model class instances under the same key, causing issues.

So I have:

class User extends BaseModel {}
class Foo extends BaseModel {}
class Bar extends BaseModel {}

But in production code, the this.constructor.name is "a" for all of them (User, Foo, Bar).

Did you try recovering your dependencies?

N/A

Environment

  current version of create-react-app: 5.0.0
  running from /Users/jashsayani/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

  System:
    OS: macOS 12.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Edge: Not Found
    Firefox: Not Found
    Safari: 15.2
  npmPackages:
    react: ^17.0.1 => 17.0.1
    react-dom: ^17.0.1 => 17.0.1
    react-scripts: 4.0.1 => 4.0.1
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

  1. Create class BaseModel and copy constructor from above.
  2. Create sub-classes User, Foo, Bar, etc.
  3. Create instances of User, Foo, Bar, etc. (const f = new Foo();)
  4. Notice that value of this.constructor.name is "a" in constructor (when creating instance of Foo, Bar, etc.) with deploy build code (NOT local server)

Expected behavior

Values of this.constructor.name should be "a", "b", "c", etc. based on different sub-classes

Actual behavior

Creating instances of multiple sub-classes results in this.constructor.name to be "a".

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions