Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider keeping class properties in loose mode #4263

Closed
gaearon opened this issue Apr 5, 2018 · 6 comments
Closed

Consider keeping class properties in loose mode #4263

gaearon opened this issue Apr 5, 2018 · 6 comments
Milestone

Comments

@gaearon
Copy link
Contributor

gaearon commented Apr 5, 2018

I was against #4248 but thought a bit more about it and now I’m not sure.

We already deviate from the spec. That’s not great, but that’s an existing problem. We can choose to address it now or we can choose to address it later.

React apps rely on class properties for defining methods and state. However Object.defineProperty is known to be relatively expensive (at least it used to be). That doesn’t mean browser’s native implementation would necessarily be expensive (I don’t think anyone measured). But that switching from existing output to new output will likely introduce performance regressions.

How severe will this regression be? I don’t know. But we need to further explore this tradeoff. In particular we might want to measure the regression on a large React project that relies a lot on class properties. If it’s significant we might want to enable loose behavior, and postpone changing it to be spec-compliant until we have some plan for addressing this.

@gaearon gaearon added this to the 2.0.0 milestone Apr 5, 2018
@gaearon
Copy link
Contributor Author

gaearon commented Apr 5, 2018

Another data point: at FB we changed it to use loose because it caused a significant bundle size regression after converting to Babel 7.

@Timer
Copy link
Contributor

Timer commented Apr 5, 2018

What if we only applied loose mode in production?

If we remain strict in development, users can develop against spec so that when they target "latest chrome version" and get native class property support, things work as expected.

Making it loose in production will prevent bundle size from increasing and not introduce potential performance regressions until this is fleshed out further in the coming months.

@gaearon
Copy link
Contributor Author

gaearon commented Apr 5, 2018

That's too big of a difference between prod and dev environment—likely to cause bugs.

@Timer
Copy link
Contributor

Timer commented Apr 5, 2018

I think we're introducing the potential for bugs in either direction -- if we go this route I think we should force the class properties transform to be on, no matter target browser support (I think we do this now).

We should add a comment to this explaining not to remove it once preset-env supports it by default (it may already):

require('@babel/plugin-proposal-class-properties').default,

@hzoo
Copy link

hzoo commented Apr 5, 2018

Yeah 👍 to changing. I was hesitant to make it default but overall that seems like the best decision as a compiler even if it means "config" for users. I guess it's what people expect already, hard to decide

@gaearon
Copy link
Contributor Author

gaearon commented Apr 5, 2018

if we go this route I think we should force the class properties transform to be on, no matter target browser support (I think we do this now)

👍 I'm cool with this.

@Timer Timer closed this as completed in 1d4fdc2 Apr 6, 2018
@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
LishuGupta652 pushed a commit to LishuGupta652/create-react-app-1 that referenced this issue Oct 8, 2024
* Enable loose mode for `class-properties`

* Update comment to point to discussion

Resolves facebook#4263
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants