-
Notifications
You must be signed in to change notification settings - Fork 4.7k
DataViews: externalize theme stylesheet #75182
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import fieldsLtr from '../package-styles/fields-ltr.lazy.scss?inline'; | |
| import fieldsRtl from '../package-styles/fields-rtl.lazy.scss?inline'; | ||
| import mediaFieldsLtr from '../package-styles/media-fields-ltr.lazy.scss?inline'; | ||
| import mediaFieldsRtl from '../package-styles/media-fields-rtl.lazy.scss?inline'; | ||
| import theme from '../package-styles/theme.lazy.scss?inline'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to consolidate this to a single
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries, consolidated in #74899! |
||
| import ui from '../package-styles/ui.lazy.scss?inline'; | ||
|
|
||
| /** | ||
|
|
@@ -60,8 +61,8 @@ const CONFIG = [ | |
| }, | ||
| { | ||
| componentIdMatcher: /^dataviews-/, | ||
| ltr: [ componentsLtr, dataviewsLtr ], | ||
| rtl: [ componentsRtl, dataviewsRtl ], | ||
| ltr: [ theme, componentsLtr, dataviewsLtr ], | ||
| rtl: [ theme, componentsRtl, dataviewsRtl ], | ||
| }, | ||
| { | ||
| componentIdMatcher: /^fields-/, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @import "../../packages/theme/src/prebuilt/css/design-tokens.css"; |
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry I overlooked this point — as far as I know these are not "loaded automatically" in WordPress, they require an
wp_enqueue_stylelike we document in the@wordpress/componentsreadme:gutenberg/packages/components/README.md
Line 28 in b054863
This is also wrong in the
@wordpress/uireadme so I'll fix.Another point is that I don't think we load the
@wordpress/themedesign tokens stylesheet in Gutenberg yet, so if DataViews actually uses anything that requires a design token, that might be broken right now 😅(cc @WordPress/gutenberg-components in case I got something wrong here)
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 thought this would be handled through the dependency chain from DataViews style loading to the
wp-themestylesheet as a dependency, i.e. what was corrected in #74743.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.
Even if the DataViews stylesheet did load the theme stylesheet (which it doesn't anymore in this PR), shouldn't a consumer need to
wp_enqueue_stylethe DataViews stylesheet at least? To ensure correct load order, at the very least? That's what's documented in the@wordpress/componentsreadme, so if that's wrong I would want to fix it.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.
Hm, the more I dig into this, the more I feel we may in-fact be missing something.
I think there's some partial truth to this. There are examples like
@wordpress/bootwhere technically WordPress is handling the "loaded automatically" by loading theme styles. But obviously this boot package isn't yet used everywhere.There may be some incidental behavior where the theme styles are brought in via dependency chains, e.g.
@wordpress/dataviews->@wordpress/ui->@wordpress/themewhich is translated into style dependencies through the build'sinferStyleDependencies. But it builds those dependencies out of imports in the JavaScript code, which is fragile and not a strong signal of what style dependencies should be loaded.How it should work? I'm not super clear, but maybe one of:
@wordpress/bootin more places as a true boot-point for "WordPress" and all its core stylinglib/client-assets.phpto includewp-themein more entrypoint packages@use "@wordpress/theme/src/prebuilt/css/design-tokens.css"throughout some more entrypoint stylesheetswpStyleDependenciesfield inpackage.jsonthat's respected by the build toolSome of those options may still require documentation that consumers would be responsible for ensuring the styles are enqueued.
cc @youknowriad @jsnajdr
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.
The way I see it is:
<ThemeProvider>should be also doing@use "@wordpress/theme/src/prebuilt/css/design-tokens.css"ThemeProviderand include the tokens CSS.ThemeProviderand tokens to all of these packages.Where I think we could improve things:
ThemeProvidershould ideally automatically inject the design tokens (once).Uh oh!
There was an error while loading. Please reload this page.
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.
It's an option, though as discussed previously in #74174 (comment) it feels like it just shifts the dependency from the a stylesheet to a React component. So a project external to WordPress that wants to use DataViews but doesn't care about theming still has to introduce a ThemeProvider wrapper somewhere.
Yeah, I think this is a logical next step. We may not strictly need the
ThemeProvidercomponent, just the styles should be enough to start. I also want to be conscious whether this ships with WordPress 7.0 and creates expectations around the theme variables; ideally we'd leave it out, but I also don't want anything to be broken if it was by these changes 😓If we did add the styles to the entrypoints, then I think it's accurate to say that this would be handled automatically inside WordPress as mentioned in the changelog note.
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.
Yes, but the main API for these components is React, so it's just simplifies things and ThemeProvider is almost already mandatory. That said, this is not the main thing in this discussion. We can live with or without it.
We do need the ThemeProvider (or more precisely the UserThemeProvider) in order to adapt to the currently selected user profile.
If you think this is too soon for 7.0, the only other option I see is to revert the usage of the UI package in dataviews.
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'm not sure if we're using anything where we need the user preference at the moment? Although yes, we should probably just go ahead and get this established.
I was going to suggest we could revert the changes made in this pull request, but (a) I'm still not entirely sure it's broken as-is, and (b) regardless, the styles would be defining
:roottheme CSS properties, so those are going to be present for everyone.I think we could probably be okay with what's shipping, especially after the latest rounds of token refinement. I'd like if we had some flexibility for revisions without too much fear of backwards-compatibility even after releasing, though I dunno how others may feel about that.
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.
As of now,
ThemeProvideris only needed if in need of customizing the default theme — otherwise, the CSS file includes all the required variables with the default theme values.I see value in not requiring
ThemeProvider, and also in the fact that using CSS variables should prevent FUOC while theThemeProviderhasn't calculcated the overridden CSS variables.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.
Important thing is that edit-site and edit-post... still update properly the colors when the user profile is modified. So if tomorrow someone starts using any component that uses colors from
@wordpress/uiin@wordpress/dataviewswe'd be introducing a bug without knowing.