-
Notifications
You must be signed in to change notification settings - Fork 670
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
feat(tailwind): Smaller bundle size #1383
Merged
Merged
Conversation
This file contains 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
gabrielmfern
added
Package: @react-email/tailwind
Type: Improvement
An improvement, that is, changes to an existing feature that improve it
labels
Mar 27, 2024
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
gabrielmfern
commented
Mar 27, 2024
gabrielmfern
commented
Mar 27, 2024
gabrielmfern
commented
Mar 27, 2024
gabrielmfern
commented
Mar 27, 2024
Co-authored-by: Benny Burrito <[email protected]> Co-authored-by: Ben Verspeak <[email protected]> Co-authored-by: Gabriel Miranda <[email protected]>
… is not installed (#1387) Co-authored-by: zhanghong <[email protected]>
…e of the Tailwind component
…enerate styles for class names
…ities instead of regexes
This function is meant to do the sanitization that we need for the best email client support. As of this commit, it only sanitizes the `rgb` calls it finds.
…name of their digit This is because the only way to have these numbers in class names for CSS is to either escape them with something like "\3". But the issue with that is that we can't really have escape characters in class selectors as they aren't very well supported.
…nts in the React tree
This was referenced Oct 7, 2024
gabrielmfern
added a commit
that referenced
this pull request
Oct 8, 2024
Co-authored-by: Ben Read <[email protected]> Co-authored-by: Benny Burrito <[email protected]> Co-authored-by: Ben Verspeak <[email protected]> Co-authored-by: hank <[email protected]> Co-authored-by: zhanghong <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Ben Gracewood <[email protected]> Co-authored-by: Victor Laforet <[email protected]> Co-authored-by: Bu Kinoshita <[email protected]> Co-authored-by: Vitor Capretz <[email protected]>
gabrielmfern
added a commit
that referenced
this pull request
Oct 11, 2024
Co-authored-by: Ben Read <[email protected]> Co-authored-by: Benny Burrito <[email protected]> Co-authored-by: Ben Verspeak <[email protected]> Co-authored-by: hank <[email protected]> Co-authored-by: zhanghong <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Ben Gracewood <[email protected]> Co-authored-by: Victor Laforet <[email protected]> Co-authored-by: Bu Kinoshita <[email protected]> Co-authored-by: Vitor Capretz <[email protected]>
gabrielmfern
added a commit
that referenced
this pull request
Oct 14, 2024
Co-authored-by: Ben Read <[email protected]> Co-authored-by: Benny Burrito <[email protected]> Co-authored-by: Ben Verspeak <[email protected]> Co-authored-by: hank <[email protected]> Co-authored-by: zhanghong <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Ben Gracewood <[email protected]> Co-authored-by: Victor Laforet <[email protected]> Co-authored-by: Bu Kinoshita <[email protected]> Co-authored-by: Vitor Capretz <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Package: @react-email/tailwind
Type: Improvement
An improvement, that is, changes to an existing feature that improve it
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.
Background
After the updates to the Tailwind component that came with performance improvements
we had a lot more environments to consider while trying to run
tailwindcss
under the hood for generating the styles from classes.
These environment constraints, like being able to run on the browser and on other environments,
forced us into having to polyfill certain node modules — that both
postcss
andtailwindcss
use under the hood — while bundling even though these code paths were never really
hit when running.
The reason these code paths were not completely tree shaken out of the built code was because
we called
tailwindcss
directly as a plugin onpostcss
.Why?
Polyfilling was the temporary solution for this, but it is not optimal in the least. This caused
issues like:
next-intl
's createTranslator with Tailwind component #1244And ended up also being a burden to maintain and debug.
The solution
The best way I've found to solve these issues is by calling out the internal Tailwind functions
that do what they need to do on
postcss
data structures. This also allows us to substitute a bit ofour logic, which was previously purely done with regexes, with
postcss
's utilities which makes it much easier to readand maintain.
The reason I choose to call out the internal Tailwind functions was because the code that was Node specific
was really just around finding the configuration or checking if a certain thing was installed, and
this would really only run when it was called as a
postcss
plugin.The way I do call out the internal Tailwind functions is heavily inspired by the way they do it
themselves on the Tailwind VS Code extension/LSP Server.
Other changes that make this a refactor
Along with this, I also had to change up a few things. The first and biggest one was applying
the non-inlinable styles — currently media queries, i.e.
sm:...
— after our first passon the React tree which is for inlining styles. This is because we are now generating the styles
for each element's classes on-the-fly instead of at once (which is still performant the way it is
implemented), so we need to aggregate all the non-inlinable classes and their CSS to add to the
<head>
later.
The second change should be mostly internal, (and should also make it easier for others to contribute),
which is a new
mapReactTree
utility that goes through the whole tree and separates the concernsabout when to go recursive on the elements or not. It will also make it easier to actually look at #1104 once
we get there.
Added tests for ensured stability
As I mentioned, we had to consider a bunch of different environments and testing them manually
was really time-consuming, so, borrowed from #1124, I implemented an integration tested powered by yalc that allows us to make sure that the component will work well with NextJS's build process.
You can find this test inside
packages/tailwind/integrations/_tests/nextjs.spec.ts
. This PR also adds a test forVite
as well.