[babel-plugin] Don't hoist $$css objects that reference local variables#1739
Open
henryqdineen wants to merge 1 commit into
Open
[babel-plugin] Don't hoist $$css objects that reference local variables#1739henryqdineen wants to merge 1 commit into
henryqdineen wants to merge 1 commit into
Conversation
The $$css object hoisting added for @stylexjs/atoms unconditionally hoists any inline object with $$css: true to module scope, even when property values reference function-scoped variables. This adds a scope check before hoisting. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@henryqdineen is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed / motivation ?
We ran into this after upgrading to 0.19.0. The
$$cssobject hoisting added in #1406 (for@stylexjs/atoms) unconditionally hoists any inline object with$$css: trueto module scope, even when its property values reference function-scoped variables.For example, this (admittedly unsupported) pattern:
Gets compiled to:
We acknowledge that using
$$cssdirectly like this is unsupported — we're actively working around it and moving away from the pattern. But since it was working before 0.19.0, we thought it would be worth patching in case anyone else hits it.This adds a
canHoistObjectcheck that verifies all identifiers referenced in the object are available at program scope before hoisting.It might also be worth considering a different approach where the hoisting only targets objects known to come from atoms compilation, rather than pattern-matching on
$$css: truein the generalstylex.propsbailout path. That way this class of issue couldn't arise at all.Please feel free to close this if you don't think it's worth fixing — it's a pretty major edge case.
Additional Context
Regression test added.
Pre-flight checklist