Skip to content
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 #1052

Merged
merged 24 commits into from
Feb 10, 2025
Merged

feat: tailwind #1052

merged 24 commits into from
Feb 10, 2025

Conversation

kellyjosephprice
Copy link
Collaborator

@kellyjosephprice kellyjosephprice commented Jan 30, 2025

PR App Ref RM-11816, RM-11739

🧰 Changes

Adds support for tailwind classes in components.

Some considerations that were taken into account:

  1. we don't want to apply tailwind preflight styles
  2. we want to allow tailwind classes in components
  3. we don't want to allow any tailwind classes to be applied to the main doc

To do this, first we pass all the component source's through a hacked up tailwind processer that generates a single stylesheet with all the tailwind classes it sees. The styles are prefixed with a single class, readme-tailwind. Then that stylesheet is injected into a style tag at the top of the main doc's content.

🧬 QA & Testing

@rafegoldberg
Copy link
Contributor

rafegoldberg commented Feb 3, 2025

Feels like TW is something we should be handling on the ReadMe side of things, rather than in the engine? (Update: although, on reading a little closer, I do see why you did it this way…)

@gkoberger
Copy link
Contributor

@kellyjosephprice
Copy link
Collaborator Author

Not sure why the snapshots changed? It looks like some padding wasn't being applied?

Comment on lines +19 to +24
const css = `
@layer theme, base, components, utilities;

@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/utilities.css" layer(utilities);
`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We're not including the 'preflight' stylesheet, which does the base restyling.

@kellyjosephprice kellyjosephprice marked this pull request as ready for review February 4, 2025 17:31
@kellyjosephprice kellyjosephprice requested review from a team and davinhazard February 4, 2025 17:32
tsconfig.json Outdated
@@ -16,7 +16,7 @@
"outDir": "dist",
"resolveJsonModule": true,
"sourceMap": true,
"target": "ES2017",
"target": "ES2018",
Copy link
Member

Choose a reason for hiding this comment

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

might want to bump this up to ES2020 where you'd get access to optional chaining. might even just go to ES2024.

Copy link
Contributor

@kevinports kevinports left a comment

Choose a reason for hiding this comment

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

This is really cool!

Had one non-blocking reservation about how this puts a <style> outside of the <head>.

processor/transform/tailwind.tsx Show resolved Hide resolved
lib/run.tsx Outdated Show resolved Hide resolved
lib/run.tsx Outdated

return {
default: () => (
<Contexts terms={terms} baseUrl={baseUrl} variables={variables}>
{!!stylesheets && stylesheets.map(stylesheet => <style>{stylesheet}</style>)}
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we're adding the <style> wherever we run rdmd right? So the markup will be something like

<div class="markdown-body">
  <style>
     ...
  </style>
  ...
</div>

It's worth noting that putting a style tag outside of the <head> is technically not valid html. Seems like it'll work fine though? We just might want to be mindful that

  1. This doesn't create any FOUC in the readme app once it's all wired up
  2. Any of our customers won't have a problem that their hub isn't going to pass strict HTML validation. Not sure if this would impact seo or a11y compliance. Probably not?

Found a whatwg thread all about this. You used to be able to use <style scoped> on some browsers for this, but it was deprecated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, that's a good point. I'd like to keep it to prevent a FOUC, but maybe I can have it portal into the head async.

IIRC, when rendering server side, we render this output and inject the html into the doc. So this component won't have access to the head until it's fully rehydrated in the client.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah true -- & having to wait till the app hydrates to tack on the stylesheet would have waaaaay more of a FOUC than what you're currently doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for this first pass it’s fine to inject these <style> tags outside of the head; we can always revisit down the line if we notice issues/get complaints!

@kellyjosephprice kellyjosephprice merged commit c197298 into next Feb 10, 2025
14 checks passed
@kellyjosephprice kellyjosephprice deleted the feat/tailwind branch February 10, 2025 17:47
rafegoldberg pushed a commit that referenced this pull request Feb 10, 2025
## Version 8.1.0
### ✨ New & Improved

* tailwind ([#1052](#1052)) ([c197298](c197298))

### 🛠 Fixes & Updates

* upgrading vitest to v3, laying ground work for vitest browser testing ([#1054](#1054)) ([75659ef](75659ef))

<!--SKIP CI-->
@rafegoldberg
Copy link
Contributor

This PR was released!

🚀 Changes included in v8.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants