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

No Tailwind selectors #1894

Merged
merged 3 commits into from
Jun 4, 2023
Merged

No Tailwind selectors #1894

merged 3 commits into from
Jun 4, 2023

Conversation

berekuk
Copy link
Collaborator

@berekuk berekuk commented Jun 3, 2023

Fixes #1892.

Built on top of #1828; this doesn't belong in that PR, but also that PR is currently subtly broken, so if we accept this change then we should merge this PR instead.

Unfortunately, this PR makes squiggle-components harder to adopt for those who don't use Tailwind. But easier for those who do use Tailwind, including our team.

This is mostly Tailwind's fault; it doesn't provide a good solution for how to scope its preflight styles.

I got lucky with this PR that the solution for Docusaurus exists: facebook/docusaurus#2961 (comment), and it works pretty well. Though I don't like that it loads an extra CSS file from the CDN. But we'll probably migrate from Docusaurus to Nextra (#1801) before this causes us any problems.

In the future, if we want to simplify the adoption of squiggle-components by non-Tailwind teams, we'll have to do something like this:

  • Write a detailed instruction on how to scope Tailwind's preflight (this requires copy-paste, like I did in the previous version of squiggle-components, or some non-standard postcss plugin).
    • Alternatively, we could bundle a scoped preflight in @quri/ui, with a default name.
  • Ask consumers to configure Tailwind to build our styles; they'll have to analyze both @quri/ui and @quri/squiggle-components for Tailwind classes, and if we ever split our packages further, consumers will have to update their tailwind.config.js file.
  • In addition to that, our modals and tooltips use portals, so they need to be scoped too; in the previous version of @quri/ui, this was done by tailwindSelector prop; in the future, this could be achieved by the top-level <TailwindContext.Provider value={{selector: "squiggle"}}>, which would be picked up by @quri/ui components and injected into portals. Then we'd have to ask squiggle-components consumers to put that provider somewhere at the top level of their app. (It's not possible to pass tailwindSelector explicitly, because modals are rendered by squiggle-components, so the necessary selector class must be passed through the provider.)

To clarify, not everyone has to include a scoped preflight for components to work. But Tailwind's non-scoped preflight is pretty aggressive (i.e., it resets h1/h2/h3 styles), so it would usually break user's other styles. In case of Docusaurus, the solution that I linked above injects Tailwind's unscoped preflight before Docusaurus global styles, which makes them compatible. In other setups, this might be harder/impossible to do.

@berekuk berekuk requested review from OAGr and Hazelfire as code owners June 3, 2023 23:05
@changeset-bot
Copy link

changeset-bot bot commented Jun 3, 2023

⚠️ No Changeset found

Latest commit: d4f97f7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Jun 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2023 0:21am
quri-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2023 0:21am
relative-values ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2023 0:21am
squiggle-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 4, 2023 0:21am
squiggle-website ✅ Ready (Inspect) Visit Preview Jun 4, 2023 0:21am

@berekuk berekuk changed the base branch from develop to definitions June 3, 2023 23:06
@berekuk
Copy link
Collaborator Author

berekuk commented Jun 3, 2023

I changed base to definitions, so that the diff on this would be more readable.

@berekuk
Copy link
Collaborator Author

berekuk commented Jun 3, 2023

To be clear, good things about this PR:

  • it removes the copy-pasted preflight from squiggle-components (which was probably getting slowly out of date)
  • no more subtle bugs with tailwindSelectors
  • no more <SquiggleContainer>

@berekuk
Copy link
Collaborator Author

berekuk commented Jun 4, 2023

In addition to that, our modals and tooltips use portals, so they need to be scoped too; in the previous version of @quri/ui, this was done by tailwindSelector prop; in the future, this could be achieved by the top-level <TailwindContext.Provider value={{selector: "squiggle"}}>, which would be picked up by @quri/ui components and injected into portals. Then we'd have to ask squiggle-components consumers to put that provider somewhere at the top level of their app. (It's not possible to pass tailwindSelector explicitly, because modals are rendered by squiggle-components, so the necessary selector class must be passed through the provider.)

This part bothered me, so I implemented <TailwindProvider> and rewrote components README file to explain how to use it.

Copy link
Contributor

@OAGr OAGr left a comment

Choose a reason for hiding this comment

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

I'm going to trust you here. Don't fully understand this, but your comment definitely seems reasonable.

At this point, I'm not very worried about non-tailwind-components-users.

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

Successfully merging this pull request may close these issues.

Get rid of .squiggle selector in squiggle-components
2 participants