Skip to content

fix(unplugin): transform .astro files that arrive already compiled - #1821

Open
wobsoriano wants to merge 4 commits into
facebook:mainfrom
wobsoriano:fix/astro-transformer-compiled-input
Open

wobsoriano wants to merge 4 commits into
facebook:mainfrom
wobsoriano:fix/astro-transformer-compiled-input

Conversation

@wobsoriano

@wobsoriano wobsoriano commented Aug 25, 2026 •

Copy link
Copy Markdown

What changed / motivation ?

I wanted to try StyleX in an Astro app and couldn't get it working. Any style I declared inside a .astro file was ignored, and the build failed with:

Error: Unexpected 'stylex.create' call at runtime.
Styles must be compiled by '@stylexjs/babel-plugin'.

It turned out the plugin picks which files to handle by file extension, and .astro isn't on the list, so those files get skipped entirely.

Supporting them doesn't need anything special. Astro turns .astro files 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 main and pass with this change:

  • one checks .astro files are picked up
  • one compiles a real .astro module and checks the CSS actually comes out

I also created a sample app with a patched @stylexjs/unplugin package (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/astro entry, or add an example in the examples folder, or I can just release a community astro-stylex integration (ref)

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 25, 2026
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

@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.

@wobsoriano
wobsoriano marked this pull request as ready for review August 25, 2026 17:32
Copilot AI lite review requested due to automatic review settings August 25, 2026 17:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .astro to the set of “transformable” module IDs via a shared isTransformableId() helper.
  • Update both transformInclude() and the early-return guard in transform() to use the new helper.
  • Add tests to verify .astro inclusion 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.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants