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.

Consider keeping class properties in loose mode

See original GitHub issue

I was against https://github.com/facebook/create-react-app/pull/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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
gaearoncommented, 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.

0reactions
hzoocommented, 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Though the "loose" option was set to "false" in your @babel ...
I'm getting this warning over and over: Though the "loose" option was set to ... mode option was set to "true" for @babel/plugin-proposal-class-properties...
Read more >
babel/plugin-transform-classes
Method assignment. Under loose mode, methods are defined on the class prototype with simple assignments instead of being defined. This can result in...
Read more >
Loose mode · Babel (5.x)
Just like method assignment in classes, in loose mode, computed property names use simple assignments instead of being defined.
Read more >
How to implement loose coupling, high cohesion in JavaScript
In this article we will use JavaScript classes to implement these design patterns and discuss why they make code more maintainable.
Read more >
Unicast Reverse Path Forwarding Loose Mode
With Unicast RPF, all equal-cost “best” return paths are considered valid, meaning that it works for cases in which multiple return paths exist, ......
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