-
Notifications
You must be signed in to change notification settings - Fork 16
Centralize all CSS imports in index.css for explicit ordering
#2035
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| background: white; | ||
| padding: 2rem; | ||
| outline: none; | ||
| } |
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.
I had copied this stuff in from Reach dialog when we switched to Radix, even though almost all of it was being overridden.
| className={({ isActive }) => | ||
| cn(linkStyles, { | ||
| '!bg-accent-secondary hover:!bg-accent-secondary-hover svg:!text-accent-tertiary': | ||
| 'text-accent !bg-accent-secondary hover:!bg-accent-secondary-hover svg:!text-accent-tertiary': |
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.
I accidentally deleted this while testing HMR performance after removing barrel files.
40d15c8 to
7e1b28d
Compare
| ], | ||
| patterns: [ | ||
| // import all CSS except index.css at top level through CSS @import statements | ||
| // to avoid bad ordering situations. See https://github.com/oxidecomputer/console/pull/2035 |
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.
converted this file to JS solely so I could put this comment here
| .DialogOverlay { | ||
| /* background: hsla(0, 0%, 0%, 0.33); */ | ||
| @apply fixed inset-0 z-10 overflow-auto bg-scrim; | ||
| } |
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.
Turned this into a DialogOverlay component.
index.css for explicit ordering
| onClick={onDismiss} | ||
| aria-hidden | ||
| /> | ||
| <DialogOverlay /> |
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.
I can't find any problem with removing this onClick and the pointer-events-auto. Everything works – clicking out to close the modal, scrolling popovers when they're inside the modal, etc. Give it a try @benjaminleonard.
index.css for explicit orderingindex.css for explicit ordering
charliepark
left a comment
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.
Clicking through, everything looks good to me
oxidecomputer/console@269c2c8...784e8aa * [784e8aac](oxidecomputer/console@784e8aac) oxidecomputer/console#2035 * [da07ce01](oxidecomputer/console@da07ce01) oxidecomputer/console#2039 * [04b56b02](oxidecomputer/console@04b56b02) oxidecomputer/console#2037 * [55a72c86](oxidecomputer/console@55a72c86) oxidecomputer/console#2036 * [f0cf2be5](oxidecomputer/console@f0cf2be5) oxidecomputer/console#2033 * [3ad46af4](oxidecomputer/console@3ad46af4) oxidecomputer/console#2032 * [cd1bff5c](oxidecomputer/console@cd1bff5c) bump playwright and react query and stuff * [08bd3fe5](oxidecomputer/console@08bd3fe5) oxidecomputer/console#2030 * [02701738](oxidecomputer/console@02701738) forgot to delete app/ui/index.ts
oxidecomputer/console@269c2c8...784e8aa * [784e8aac](oxidecomputer/console@784e8aac) oxidecomputer/console#2035 * [da07ce01](oxidecomputer/console@da07ce01) oxidecomputer/console#2039 * [04b56b02](oxidecomputer/console@04b56b02) oxidecomputer/console#2037 * [55a72c86](oxidecomputer/console@55a72c86) oxidecomputer/console#2036 * [f0cf2be5](oxidecomputer/console@f0cf2be5) oxidecomputer/console#2033 * [3ad46af4](oxidecomputer/console@3ad46af4) oxidecomputer/console#2032 * [cd1bff5c](oxidecomputer/console@cd1bff5c) bump playwright and react query and stuff * [08bd3fe5](oxidecomputer/console@08bd3fe5) oxidecomputer/console#2030 * [02701738](oxidecomputer/console@02701738) forgot to delete app/ui/index.ts
Changes
index.cssfile so we can control the orderapp/ui/styles— this is debatable, I guess they could still live next to their components, but mehWhy
postcss-import is a PostCSS plugin that takes all your CSS
@importstatements and inlines them into a single file. If you're just working with CSS files importing other CSS files, the order should be straightforward: depth-first traversal of the import tree. Vite also, somewhat magically, inlines CSS files imported into TypesSript files. We were importing CSS that way sometimes so the CSS would be right next to the relevant code, e.g., importing the button CSS inButton.tsx. The problem, as far as I can tell, is that with imports into TS files, the order that things get inlined into the final CSS output is not well-defined, or at least not easy to predict.In #1978, I shuffled a bunch of files around and moved the import of the main CSS bundle from the now-deceased UI barrel file all the way up to
main.tsx, and this seems to have caused the order that CSS imports were inlined into the bundle to change, which broke button styling by failing to put it after the base Tailwind styles it is meant to override.Bad
Good
The selectors, being single classes, were not more specific than the base Tailwind styles. Make them more specific could be one approach to fixing this.
At this point the Tailwind expert should ask: isn't this what
@layeris for? Yes, this is what@layeris for. Unfortunately, when you're mixing imports into CSS and imports into TSX,postcss-importdoesn't see to be executing correctly, so when it see@layerin a the CSS file imported into TS, it doesn't seem to know that the necessary@tailwindis present over in another CSS file.It does not give this error on
@layerif the same CSS file is imported directly intoindex.cssinstead, but once we're doing it all in CSS, we control the order anyway, so we don't need@layer.I think the fact that this worked before was basically luck. Looking at the compiled CSS output from a "good" deploy, the base TW stuff is still not at the beginning of the file, it just happens to be somewhere in the middle and the button CSS goes after it. It's good that we turned up this problem now when it wasn't particularly inconvenient and we have time to fix it.