[postcss-plugin] Implement custom importSources for React Strict DOM compatibility#1063
Merged
necolas merged 1 commit intoMay 16, 2025
Merged
Conversation
1 task
javascripter
commented
May 16, 2025
| include, | ||
| exclude, | ||
| useCSSLayers = false, | ||
| importSources = ['@stylexjs/stylex', 'stylex'], |
Contributor
Author
There was a problem hiding this comment.
Strictly speaking, we only need "stylex" to maintain backward compatibility as that was the default. In other places like eslint plugin, we use @stylexjs/stylex as the default value so I added both @stylexjs/stylex and stylex to reduce confusion.
If we're okay with breaking some backward compatibility, we can just use @stylexjs/stylex to align.
| filename: id, | ||
| caller: { | ||
| name: '@stylexjs/postcss-plugin', | ||
| platform: 'web', |
Contributor
Author
There was a problem hiding this comment.
https://facebook.github.io/react-strict-dom/learn/setup/#babel-configuration
RSD instructs users to configure babel.config.js which extract api.caller(caller => caller && caller.platform), so this just passes the correct value.
necolas
approved these changes
May 16, 2025
c1c6a10 to
061bb87
Compare
This was referenced May 17, 2025
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 ?
This PR adds
importSourcesoption to be configurable in order to allow reusing the plugin for react-strict-dom, and setsplatform: "web"as babel.caller as required by RSD babel preset.react-strict-dom currently relies on a community-maintained package postcss-react-strict-dom that I maintain to extract styles statically.
I'm intending to upstream the PostCSS plugin to RSD but the initial attempt required forking the plugin instead of simply re-exporting the plugin with pre-defined config because
shouldTransform()function currently skips files that do not matchstylex. This leads to additional maintenance burden and is not ideal.By allowing
importSourcesto be configurable, RSD users can now use this plugin with the following config:After this PR gets merged, on RSD side we can create
react-strict-dom/postcss-pluginthat re-exports@stylexjs/postcss-pluginso that additional config remains implementation detail for the user.This strategy seems to be aligned with the strategy necolas is considering for RSD's eslint plugin as well.
Linked PR/Issues
react/react-strict-dom#281 (comment)
react/react-strict-dom#282
Additional Context
I checked this PR makes the plugin compatible with RSD by:
Then, modify
postcss.config.jsto use this plugin:The example now renders correctly using the official
@stylexjs/postcss-plugin:Pre-flight checklist
Contribution Guidelines