Skip to content

Transform class static blocks in the Babel preset - #59854

Open
lazerg wants to merge 3 commits into
react:mainfrom
lazerg:fix/issue-59853-class-static-block
Open

lazerg wants to merge 3 commits into
react:mainfrom
lazerg:fix/issue-59853-class-static-block

Conversation

@lazerg

@lazerg lazerg commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary:

@react-native/babel-preset runs the class features plugins (transform-private-methods and transform-private-property-in-object, plus transform-class-properties when classes are lowered) but not @babel/plugin-transform-class-static-block. Those plugins throw "Static class blocks are not enabled" on any class with a static { } block, so an app file or dependency using one fails to bundle. The preset now adds the static block plugin next to the private methods plugin, so it only runs when the class features plugins do. With unstable_preserveClassPrivate the block is still left as is, like before.

Fixes #59853

Changelog:

[GENERAL] [FIXED] - Babel preset no longer fails on class static blocks

Test Plan:

Added tests for a class with a static block under the hermes-stable and hermes-legacy profiles; both fail with "Static class blocks are not enabled" before the change. jest packages/react-native-babel-preset passes and the existing transform snapshots are unchanged. The plugin's ^7.26.0 range is already in yarn.lock, so the lockfile doesn't change.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 7, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 7, 2026
@javache
javache requested a review from robhogan November 9, 2026 10:57
@vzaidman

vzaidman commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

I think this is needed, but the tests only cover a public static field. A static block touching a #private field or super is the ordering-sensitive case (static-block plugin runs before private-methods) worth one test, plus a test asserting the hermes-stable + preserveClassPrivate path leaves the block intact.

@vzaidman
vzaidman requested a review from cipolleschi November 9, 2026 11:59
@lazerg

lazerg commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, added both: one test with a #private field and super in a static block, and one checking that hermes-stable with preserveClassPrivate leaves the block alone. Both passed without touching the plugin order.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@react-native/babel-preset fails on class static blocks: "Static class blocks are not enabled"

3 participants