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

Events: Clean up stylesheet #1172

Merged
merged 6 commits into from
Dec 12, 2023
Merged

Events: Clean up stylesheet #1172

merged 6 commits into from
Dec 12, 2023

Conversation

renintw
Copy link
Contributor

@renintw renintw commented Dec 11, 2023

This PR cleans up unused and duplicate selectors as well as standardizes the use of media queries within selectors.
The original code was a mix of media queries inside and outside of selectors, and this update makes it consistent.
This change will enhance clarity and maintainability for future style adjustments or additions.
For instance, when previously adjusting the cover for different breakpoints, this format proved to be very understandable.

Additionally, this PR also fixes linting errors and breaks out the styles in wporg-google-map.pcss that aren't related to the map into event-list.pcss.

@StevenDufresne
Copy link
Contributor

If you are cleaning this up, does it make sense to break out the css that isn't related to the map? The context is that we were using the map component but no longer doing so for the events list.

@renintw renintw force-pushed the enhance/clean-up-stylesheet branch from c752968 to 20e6a3d Compare December 11, 2023 15:15
@renintw renintw requested a review from adamwoodnz December 11, 2023 15:25
@renintw renintw added this to the Events: Promotion milestone Dec 11, 2023
@renintw
Copy link
Contributor Author

renintw commented Dec 11, 2023

For the first two commits: You can test whether the event list on the front page is broken.
For the third: Test if the contributor section on the front page is broken.
For the fourth: Test if the Cover part on the front page is broken. (Including Title, subtext, Map, and Events stats)
For the last two commits: You can easily tell if there's any issue by checking the code changes.

@renintw renintw requested a review from iandunn December 11, 2023 15:37
@renintw renintw changed the title Clean up stylesheet - wporg-google-map.scss Events: Clean up stylesheet Dec 11, 2023
Copy link
Member

@iandunn iandunn left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻


.wporg-marker-list-item__location::after {

@media (--small-only), (--large) {
Copy link
Member

Choose a reason for hiding this comment

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

TIL you can apply a rule to multiple queries, nice!

@@ -0,0 +1,106 @@
.wporg-marker-list__container {
Copy link
Member

Choose a reason for hiding this comment

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

Moving the list rules into their own file is great for organization, thanks!

}
}

& .wp-block-wporg-google-map {
Copy link
Member

Choose a reason for hiding this comment

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

🤔 I thought PostCSS required using &. Is that no longer the case?

https://preset-env.cssdb.org/features/#nesting-rules

Copy link
Contributor Author

@renintw renintw Dec 12, 2023

Choose a reason for hiding this comment

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

I remember for PostCSS you can use "&" only after installing plugins like postcss-nested or postcss-scss, and it seems there isn't a rule explicitly stating that "&" is mandatory in SCSS except for pseudo-classes.

And when looking into this, though I still couldn't find any clear statements stating that "&" must or must not be used, I discovered that native CSS has started supporting the use of nesting directly. It's explicitly mentioned here that using "&" and not using it is equivalent. Major browsers have already begun supporting this feature.

Also I noticed that in the link you shared, there's a "specification" linking to the same W3C draft that the Google Docs references. But I also didn't find any clear instructions in that draft saying that the "&" is absolutely required or not required, though.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like browser support for it without & is only 2%, so it seems like we won't be able to use that for a long time. Can you check the built CSS to see if it gets converted to unnested rules when & is not used?

If it is being converted to unnested vanilla CSS, then removing the & seems fine, but otherwise I think we should keep it so that the layout doesn't break for folks using recent browsers.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to remove nesting where possible. Additionally, I would vote to update this theme to match our other themes which use .scss. This potential "gotcha" for future developers is no longer an issue and we have more consistency across the child themes.

Copy link
Contributor Author

@renintw renintw Dec 13, 2023

Choose a reason for hiding this comment

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

It looks like browser support for it without & is only 2%, so it seems like we won't be able to use that for a long time. Can you check the built CSS to see if it gets converted to unnested rules when & is not used?

I mentioned the support for nesting CSS earlier just to share that eventually, we will be able to write nested CSS directly in native CSS. But I think that before W3C officially transitions from a Working Draft to a Standard, these Preprocessor Tools (like SCSS, PostCSS) won't convert styles into nested CSS. And I feel that in the future, they might not even need to, unless converting to nested CSS proves to be more efficient. As it stands, the current method of conversion (completely unnested CSS) is already supported by all browsers.

I've checked the built CSS files in this repo, and they are still unnested.

Copy link
Member

Choose a reason for hiding this comment

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

We should try to remove nesting where possible.

Why is that? I think it's a convenient way to keep things properly scoped, and it's makes things much easier to read for me, similar to indenting a for loop in PHP.

update this theme to match our other themes which use .scss.

What's gotcha are you referring to?

I think the ideal would be the opposite: migrating SASS themes to PostCSS.

We originally agreed on doing that when we built the News theme, but then ended up using SASS b/c it was copy/pasta from Blockbase, and then we were too far into it make the switch while we had deadlines.

In my mind SASS is tech debt while PostCSS is future-proofed.

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 the ideal would be the opposite: migrating SASS themes to PostCSS.

We originally agreed on doing that when we built the News theme, but then ended up using SASS b/c it was copy/pasta from Blockbase, and then we were too far into it make the switch while we had deadlines.

In my mind SASS is tech debt while PostCSS is future-proofed.

TIL, thanks for these links

Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to remove nesting where possible.
Why is that? I think it's a convenient way to keep things properly scoped, and it's makes things much easier to read for me, similar to indenting a for loop

  • Nesting typically leads to longer than necessary css chains
  • Nesting typically reduces the ability reuse css, leading to more styles
  • Nested CSS can be harder to read

What's gotcha are you referring to?

This conversation about whether & is needed for nested selectors.

I think the ideal would be the opposite: WordPress/wporg-parent-2021#1.

I'm not suggesting we need to stick with .scss. I'm suggesting we remain consistent. As Gutenberg matures, I expect we will be writing less CSS and feel consistency (provided it is working and not an obvious dead end) trumps difference. If we want to transition away from .scss, let's log that so we can all be on the same page.

@renintw renintw merged commit 130a1f5 into production Dec 12, 2023
3 checks passed
@renintw renintw deleted the enhance/clean-up-stylesheet branch December 12, 2023 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants