Skip to content

Conversation

@henryqdineen
Copy link
Collaborator

@henryqdineen henryqdineen commented Aug 20, 2025

What changed / motivation ?

We are evaluating StyleX and I ran into a bug in our WIP bundler integration that was caused by processStylexRules mutating rule objects. We were caching rules in memory and it caused broken behavior for incremental compilations.

My fix in this PR is to remove the mutation of the rules. I have considered that consumers could just clone the rules before they pass it to processStylexRules() but I think it is better to remove the mutation so others don't run into similar hard to track down bugs.

My fix is fairly naive in that it always shallow clones the styleObj. I was favoring simplicity here but if we want to be more perf conscious I have a version that only clones when necessary.

I don't love the unit test but it serves its purpose. If you would prefer I could add a unit test that more closely recreates the issue I was seeing.

Thanks!

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 Aug 20, 2025
@necolas
Copy link
Contributor

necolas commented Aug 20, 2025

Did you try creating a deep clone of the rules at the very top of the processStylexRules function? I believe the metadata can be serialized, so JSON.parse(JSON.stringify(rules)) might be all that's needed. In a large codebase the rules object can get very large, so it might be really slow.

@henryqdineen
Copy link
Collaborator Author

Did you try creating a deep clone of the rules at the very top of the processStylexRules function?

No but I would expect that you work but be less performant. I find the JSON.stringify() can be especially slow with large object. Are you suggesting me to implement that in this PR?

@henryqdineen
Copy link
Collaborator Author

Thanks @nmn! I just rebased and fixed the conflict.

@mellyeliu mellyeliu merged commit be0c753 into facebook:main Sep 11, 2025
7 of 9 checks passed
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.

4 participants