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

Babel: transpile class properties for wider browser support #2749

Merged

Conversation

belgattitude
Copy link
Contributor

@belgattitude belgattitude commented Feb 4, 2023

According to caniuse.com, support of public class fields is around 92%, see https://caniuse.com/?search=class%20fields.

Enable transpilation of public class properties in babel.

See https://babel.dev/docs/en/babel-plugin-proposal-class-properties

Linked to #2748

Before

Class properties in the dist

image

After

Class properties are transpiled

image

Sizes

Seems a very small size increase: 76505 vs 76444 bytes (in the esm build)

ls -la ./dist
// with class properties in babel
-rw-rw-r-- 1 sebastien sebastien 78461 févr.  4 14:43 index-455b51ca.cjs.prod.js
-rw-rw-r-- 1 sebastien sebastien 78504 févr.  4 14:43 index-6442a2a3.cjs.dev.js
-rw-rw-r-- 1 sebastien sebastien 76505 févr.  4 14:43 index-7dbf758c.esm.js
-rw-rw-r-- 1 sebastien sebastien  9186 févr.  4 14:43 react-three-fiber.cjs.dev.js
-rw-rw-r-- 1 sebastien sebastien    42 févr.  4 14:43 react-three-fiber.cjs.d.ts
-rw-rw-r-- 1 sebastien sebastien   196 févr.  4 14:43 react-three-fiber.cjs.js
-rw-rw-r-- 1 sebastien sebastien  9187 févr.  4 14:43 react-three-fiber.cjs.prod.js
-rw-rw-r-- 1 sebastien sebastien  7708 févr.  4 14:43 react-three-fiber.esm.js



// Without class properties in babel
-rw-rw-r-- 1 sebastien sebastien 78400 févr.  4 14:52 index-661b9d11.cjs.prod.js
-rw-rw-r-- 1 sebastien sebastien 78443 févr.  4 14:52 index-bf8a2906.cjs.dev.js
-rw-rw-r-- 1 sebastien sebastien 76444 févr.  4 14:52 index-fb77d67d.esm.js
-rw-rw-r-- 1 sebastien sebastien  9186 févr.  4 14:52 react-three-fiber.cjs.dev.js
-rw-rw-r-- 1 sebastien sebastien    42 févr.  4 14:52 react-three-fiber.cjs.d.ts
-rw-rw-r-- 1 sebastien sebastien   196 févr.  4 14:52 react-three-fiber.cjs.js
-rw-rw-r-- 1 sebastien sebastien  9187 févr.  4 14:52 react-three-fiber.cjs.prod.js
-rw-rw-r-- 1 sebastien sebastien  7708 févr.  4 14:52 react-three-fiber.esm.js
sebastien@sebastien-ThinkPad-P1-Gen-3:~/github/react-three-fiber/packages/fiber/dist$ 

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 4, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit b664423:

Sandbox Source
example Configuration

@belgattitude
Copy link
Contributor Author

See also #2748 (comment)

@belgattitude belgattitude changed the title chore: transpile class properties Babel: transpile class properties for wider browser support Feb 4, 2023
@CodyJasonBennett
Copy link
Member

Everything looks good here. This is all I'm seeing changing in the build (without the code change from #2748). The static transform looks a little weird, but it doesn't look to break tree-shaking.

class ErrorBoundary extends React.Component {
  constructor(...props) {
    super(...props)
    this.state = {
      error: false,
    }
  }
  componentDidCatch(err) {
    this.props.set(err)
  }
  render() {
    return this.state.error ? null : this.props.children
  }
- static getDerivedStateFromError = () => ({
-   error: true
- });
}
+ErrorBoundary.getDerivedStateFromError = () => ({
+  error: true,
+})

Thanks, I'll keep an eye out on bettering transpilation here. We target es2018 rather than use a browserslist in repos that use Vite/Rollup.

@CodyJasonBennett CodyJasonBennett merged commit e673830 into pmndrs:master Feb 4, 2023
@belgattitude
Copy link
Contributor Author

The static transform looks a little weird.

Yep, old times :)

But it doesn't look to break tree-shaking.

Good to know.

renovate bot referenced this pull request in ziyadedher/ziyadedher Feb 5, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@react-three/fiber](https://github.com/pmndrs/react-three-fiber) |
[`8.10.1` ->
`8.10.4`](https://renovatebot.com/diffs/npm/@react-three%2ffiber/8.10.1/8.10.4)
|
[![age](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/compatibility-slim/8.10.1)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/confidence-slim/8.10.1)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>pmndrs/react-three-fiber</summary>

###
[`v8.10.4`](https://github.com/pmndrs/react-three-fiber/releases/tag/v8.10.4)

[Compare
Source](https://github.com/pmndrs/react-three-fiber/compare/v8.10.3...v8.10.4)

#### What's Changed

- fix: transpile class properties for wider browser support by
[@&#8203;belgattitude](https://github.com/belgattitude) in
[https://github.com/pmndrs/react-three-fiber/pull/2749](https://github.com/pmndrs/react-three-fiber/pull/2749)

**Full Changelog**:
pmndrs/react-three-fiber@v8.10.3...v8.10.4

###
[`v8.10.3`](https://github.com/pmndrs/react-three-fiber/releases/tag/v8.10.3)

[Compare
Source](https://github.com/pmndrs/react-three-fiber/compare/@react-three/fiber@8.10.2...v8.10.3)

##### What's Changed

- fix(types): add loadAsync to Loader interface by
[@&#8203;Methuselah96](https://github.com/Methuselah96) in
[https://github.com/pmndrs/react-three-fiber/pull/2742](https://github.com/pmndrs/react-three-fiber/pull/2742)
- fix: refactor ErrorBoundary to not use public class fields by
[@&#8203;belgattitude](https://github.com/belgattitude) in
[https://github.com/pmndrs/react-three-fiber/pull/2748](https://github.com/pmndrs/react-three-fiber/pull/2748)

##### New Contributors

- [@&#8203;belgattitude](https://github.com/belgattitude) made their
first contribution in
[https://github.com/pmndrs/react-three-fiber/pull/2748](https://github.com/pmndrs/react-three-fiber/pull/2748)

**Full Changelog**:
pmndrs/react-three-fiber@v8.10.1...v8.10.3

###
[`v8.10.2`](https://github.com/pmndrs/react-three-fiber/releases/tag/v8.10.2)

[Compare
Source](https://github.com/pmndrs/react-three-fiber/compare/@react-three/fiber@8.10.1...@react-three/fiber@8.10.2)

#### What's Changed

- fix: portal injects by [@&#8203;drcmda](https://github.com/drcmda)
in
pmndrs/react-three-fiber@0c288ba
- fix(RTTR): backport traverse, update fixes by
[@&#8203;CodyJasonBennett](https://github.com/CodyJasonBennett) in
[#&#8203;2736](https://github.com/pmndrs/react-three-fiber/issues/2736)

**Full Changelog**:
pmndrs/react-three-fiber@v8.10.1...v8.10.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/ziyadedher/ziyadedher).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTkuNSIsInVwZGF0ZWRJblZlciI6IjM0LjEyMi4xIn0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
ziyadedher referenced this pull request in ziyadedher/ziyadedher Dec 16, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@react-three/fiber](https://github.com/pmndrs/react-three-fiber) |
[`8.10.1` ->
`8.10.4`](https://renovatebot.com/diffs/npm/@react-three%2ffiber/8.10.1/8.10.4)
|
[![age](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/compatibility-slim/8.10.1)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/npm/@react-three%2ffiber/8.10.4/confidence-slim/8.10.1)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>pmndrs/react-three-fiber</summary>

###
[`v8.10.4`](https://github.com/pmndrs/react-three-fiber/releases/tag/v8.10.4)

[Compare
Source](https://github.com/pmndrs/react-three-fiber/compare/v8.10.3...v8.10.4)

#### What's Changed

- fix: transpile class properties for wider browser support by
[@&#8203;belgattitude](https://github.com/belgattitude) in
[https://github.com/pmndrs/react-three-fiber/pull/2749](https://github.com/pmndrs/react-three-fiber/pull/2749)

**Full Changelog**:
pmndrs/react-three-fiber@v8.10.3...v8.10.4

###
[`v8.10.3`](https://github.com/pmndrs/react-three-fiber/releases/tag/v8.10.3)

[Compare
Source](https://github.com/pmndrs/react-three-fiber/compare/@react-three/fiber@8.10.2...v8.10.3)

##### What's Changed

- fix(types): add loadAsync to Loader interface by
[@&#8203;Methuselah96](https://github.com/Methuselah96) in
[https://github.com/pmndrs/react-three-fiber/pull/2742](https://github.com/pmndrs/react-three-fiber/pull/2742)
- fix: refactor ErrorBoundary to not use public class fields by
[@&#8203;belgattitude](https://github.com/belgattitude) in
[https://github.com/pmndrs/react-three-fiber/pull/2748](https://github.com/pmndrs/react-three-fiber/pull/2748)

##### New Contributors

- [@&#8203;belgattitude](https://github.com/belgattitude) made their
first contribution in
[https://github.com/pmndrs/react-three-fiber/pull/2748](https://github.com/pmndrs/react-three-fiber/pull/2748)

**Full Changelog**:
pmndrs/react-three-fiber@v8.10.1...v8.10.3

###
[`v8.10.2`](https://github.com/pmndrs/react-three-fiber/releases/tag/v8.10.2)

[Compare
Source](https://github.com/pmndrs/react-three-fiber/compare/@react-three/fiber@8.10.1...@react-three/fiber@8.10.2)

#### What's Changed

- fix: portal injects by [@&#8203;drcmda](https://github.com/drcmda)
in
pmndrs/react-three-fiber@0c288ba
- fix(RTTR): backport traverse, update fixes by
[@&#8203;CodyJasonBennett](https://github.com/CodyJasonBennett) in
[#&#8203;2736](https://github.com/pmndrs/react-three-fiber/issues/2736)

**Full Changelog**:
pmndrs/react-three-fiber@v8.10.1...v8.10.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://app.renovatebot.com/dashboard#github/ziyadedher/ziyadedher).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTkuNSIsInVwZGF0ZWRJblZlciI6IjM0LjEyMi4xIn0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
itsdouges pushed a commit to itsdouges/react-three-fiber that referenced this pull request Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants