-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add react-strict-dom/postcss-plugin #282
base: main
Are you sure you want to change the base?
Conversation
af8ece6
to
0fb8332
Compare
0fb8332
to
0e13940
Compare
@@ -0,0 +1,182 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unchanged from @stylexjs/postcss-plugin
// Determines if the source code should be transformed based on the presence of StyleX/RSD imports. | ||
function shouldTransform(sourceCode) { | ||
return ( | ||
sourceCode.includes('stylex') || sourceCode.includes('react-strict-dom') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added react-strict-dom check
*/ | ||
|
||
const babel = require('@babel/core'); | ||
const reactStrictBabelPreset = require('react-strict-dom/babel-preset'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced StyleX Plugin with RSD Babel Preset to match behaviors exactly as described in docs
filename: id, | ||
caller: { | ||
name: 'react-strict-dom/postcss-plugin', | ||
platform: 'web', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
platform: 'web'
is necessary for RSD Preset to process source code with StyleX
function bundle({ useCSSLayers }) { | ||
const rules = Array.from(styleXRulesMap.values()).flat(); | ||
|
||
const css = reactStrictBabelPreset.generateStyles(rules); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uses RSD Babel Preset here as well
}) => { | ||
include = [ | ||
// Include the React Strict DOM package's source files by default | ||
require.resolve('react-strict-dom'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include react-strict-dom by default, same as postcss-react-strict-dom
Why
#281 (comment)
Based on the discussion, I'm moving postcss-react-strict-dom to the official repo to make it easier for maintainers to make changes.
How
packages/react-strict-dom/postcss/plugin.js
react-strict-dom/postcss-plugin
in package.jsonapps/examples
to use the official plugin and removed postcss-react-strict-dom dependencyI initially tried to re-export the postcss plugin as described here, but found that I needed to make modifications to the internals of the plugin, so I copied the source code from StyleX repository and made necessary modifications to make it work with RSD instead.
(Changes from StyleX PostCSS Plugin will be in PR comments)
Test Plan
cd apps/example && npm run dev:web
both from the original repo and this branch and compare side-by-side to make sure output matchesLeft is original, right is this branch