Skip to content

Conversation

@henryqdineen
Copy link
Contributor

@henryqdineen henryqdineen commented Dec 3, 2025

What changed / motivation ?

This PR makes a couple changes to improve the treeshakability of the @stylexjs/stylex package.

  • Set sideEffects flag to false in the package.json. Although rare in typical usage this would allow bundlers to remove unused imports from '@stylexjs/stylex'. This is also a general best practice if the library has no side effects. I noticed that styleq already has this flag set
  • Moved the code that patches properties onto legacyMerge into a IIFE and annotated it with /*@__PURE__*/ with a rollup plugin. Even with sideEffect: false set some bundlers (definitely webpack from my testing) would consider setting a property like _legacyMerge.create = to be a side effect and the code would not be marked for dead code elimination. I tried adding/*@__PURE__*/ in the source but it was not being preserved, so I resorted to a rollup plugin. I think there is something I couldn't easily figure out about the flow or hermes-parser plugins that remove comments.

With webpack and this change I am seeing a bundle size reduction from 3.4KB to 1.4KB for a simple entry point that only uses the props import (webpack is able to analyze namespace imports in most cases)

import * as stylex from '@stylexjs/stylex';
console.log(stylex.props)

Questions

  • Can we just drop legacyMerge or at least the patching of the variables onto it? It seems undocumented?

Pre-flight checklist

@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 Dec 3, 2025
@nmn
Copy link
Collaborator

nmn commented Dec 11, 2025

Can we just drop legacyMerge or at least the patching of the variables onto it? It seems undocumented?

We're already discussing this...

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants