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

Move to Lightning CSS and upgrade to PostCSS 8 #5093

Merged
merged 22 commits into from
Sep 21, 2023
Merged

Move to Lightning CSS and upgrade to PostCSS 8 #5093

merged 22 commits into from
Sep 21, 2023

Conversation

devongovett
Copy link
Member

@devongovett devongovett commented Sep 18, 2023

This is a reduced/updated version of #3018 and #4645. It swaps most of our CSS processing to Lightning CSS, which allows us to more easily upgrade to PostCSS 8 (unblocking things like Tailwind examples in the repo).

  • The non-standard nesting syntax (postcss-nested) was replaced with the official CSS nesting syntax.
  • @inherits, @extend, and @mixin postcss plugins have been replaced with the CSS modules composes property. Rather than duplicating the declarations from the extended rule, this causes both classes to be applied on the element that uses the composed class. Beware that this can cause differences in specificity.
  • The :focus-ring pseudo class has been changed to the now-standard :focus-visible, which is processed by Lightning CSS to be replaced with our .focus-ring class as before.
  • The :hover pseudo class is now always replaced with .is-hovered, whereas before it was only done in release/storybook and not in the docs. Now the docs have a bit of JavaScript that applies the hover class in places that are server rendered. That is done by setting the data-hover attribute to the hover class. This means the docs now works as the rest of RSP in regards to touch devices and hover states.
  • Logical properties are now compiled differently. dir nesting is now possible, and in many cases, we don't even need to compile them since most individual properties are already supported natively except a few (e.g. border radius).

The remaining PostCSS plugins are:

  • postcss-import, due to some differences with how Parcel bundles. Eventually we can swap over to composes: className from "..." syntax.
  • postcss-custom-properties to inline custom properties defined in :root selectors
  • Our custom postcss-custom-properties-mapping and postcss-custom-properties-passthrough (ie xvar) plugins, which inline spectrum variables with fallback.

Potentially we can get rid of the rest of these later but it will require more refactoring to our source CSS. For now, getting rid of most of the other plugins made upgrading to PostCSS 8 much easier.

@rspbot
Copy link

rspbot commented Sep 19, 2023

}

.spectrum-Button {
@inherit: %spectrum-BaseButton;
@inherit: %spectrum-FocusRing;
composes: spectrum-BaseButton spectrum-FocusRing;
Copy link
Member

Choose a reason for hiding this comment

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

so how does this actually work? it looks like the spectrum-FocusRing being applied has the same hash prefix as spectrum-Button but I was expecting it to have a different hash that matched the focus ring stylesheet's hash if it was just applying that classname to the element. Instead it seems as though it was copied into the button CSS and then applied? even though your comment in the description would suggest otherwise.

Am I just misunderstanding how the hash is determined and it's no longer specific to the file it came from?

Copy link
Member Author

Choose a reason for hiding this comment

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

At the moment it will be duplicated due to postcss-import. That runs before CSS modules get processed, so it'll look like a single file and thus get the same hash. Whereas before it would have been merged into the .spectrum-Button selector now it is a separate selector, but there will be a separate instance of it per package right now.

packages/@react-spectrum/label/src/Field.tsx Show resolved Hide resolved
snowystinger
snowystinger previously approved these changes Sep 19, 2023
# Conflicts:
#	packages/@react-spectrum/toast/src/Toaster.tsx
@rspbot
Copy link

rspbot commented Sep 21, 2023

@rspbot
Copy link

rspbot commented Sep 21, 2023

@rspbot
Copy link

rspbot commented Sep 21, 2023

## API Changes

unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }

@devongovett devongovett merged commit 5fe7f6a into main Sep 21, 2023
26 checks passed
@devongovett devongovett deleted the lightningcss branch September 21, 2023 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants