fix(unplugin): transform .astro files that arrive already compiled - #1821
Open
wobsoriano wants to merge 4 commits into
Open
wobsoriano wants to merge 4 commits into
wobsoriano wants to merge 4 commits into
Conversation
|
@wobsoriano is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Pull request overview
This PR fixes @stylexjs/unplugin behavior in Astro projects by ensuring modules with a .astro ID are included in the plugin’s transform pipeline, preventing uncompiled stylex.create calls from reaching runtime.
Changes:
- Add
.astroto the set of “transformable” module IDs via a sharedisTransformableId()helper. - Update both
transformInclude()and the early-return guard intransform()to use the new helper. - Add tests to verify
.astroinclusion and end-to-end CSS emission from a compiled.astro-identified module.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/@stylexjs/unplugin/src/core.js | Extends transform targeting to include .astro module IDs and centralizes the ID check. |
| packages/@stylexjs/unplugin/tests/unplugin.test.js | Adds coverage ensuring .astro IDs are included and StyleX compilation produces CSS output. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…er-compiled-input # Conflicts: # packages/@stylexjs/unplugin/__tests__/unplugin.test.js
This branch has not been deployed
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 ?
I wanted to try StyleX in an Astro app and couldn't get it working. Any style I declared inside a
.astrofile was ignored, and the build failed with:It turned out the plugin picks which files to handle by file extension, and
.astroisn't on the list, so those files get skipped entirely.Supporting them doesn't need anything special. Astro turns
.astrofiles into plain JavaScript before any bundler plugin runs, so by the time this plugin sees them they're ordinary modules. Adding the extension is enough.Linked PR/Issues
Fixes # (issue)
Additional Context
Two new ones. Both fail on
mainand pass with this change:.astrofiles are picked up.astromodule and checks the CSS actually comes outI also created a sample app with a patched
@stylexjs/unpluginpackage (repo, demo)NOTE: Even with the fix, an Astro app still needs a little glue to get the stylesheet onto the page. In dev the plugin adds its styles through a hook Astro doesn't use, and in a build it appends its rules to an existing stylesheet, so a site without one ends up with a CSS file nothing links to. Neither fails loudly, you just get an unstyled page.
Happy to follow up with an
@stylexjs/unplugin/astroentry, or add an example in the examples folder, or I can just release a community astro-stylex integration (ref)Pre-flight checklist
Contribution Guidelines