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

refactor(v2): improve semantic markup of blog #2003

Merged
merged 2 commits into from
Nov 17, 2019

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Nov 16, 2019

Motivation

Fully semantic layout of blog pages. Search robots will be satisfied 😃

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

See HTML markup, no UI changes.

@lex111 lex111 added the pr: polish This PR adds a very minor behavior improvement that users will enjoy. label Nov 16, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Nov 16, 2019
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Nov 16, 2019

Deploy preview for docusaurus-2 ready!

Built with commit 83eeafc

https://deploy-preview-2003--docusaurus-2.netlify.com

@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Nov 16, 2019

Deploy preview for docusaurus-preview ready!

Built with commit 83eeafc

https://deploy-preview-2003--docusaurus-preview.netlify.com

@@ -21,16 +21,14 @@ function BlogListPage(props) {
<div className="col col--8 col--offset-2">
{items.map(
({content: BlogPostContent, metadata: blogPostMetadata}) => (
<div
Copy link
Contributor

Choose a reason for hiding this comment

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

What's wrong with a wrapper div?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not needed, we can insert the CSS class directly into the article tag, why an extra tag (div)?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, the <div> is there so that we can add margin. If we don't need to add margin of course not having a div is better.

@@ -92,13 +93,13 @@ function BlogPostItem(props) {
};

return (
<div>
<article {...attrs}>
Copy link
Contributor

@yangshun yangshun Nov 16, 2019

Choose a reason for hiding this comment

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

No, we don't want to channel props through components, it makes it harder to know what props are being used and which aren't. Accepting className props is also an anti-pattern that we don't want to encourage. If article defines its own className in future, it will work when the parents don't pass in a className but will break when the parents do. This kind of bugs are hard to detect and reliably prevent, so we don't want to allow that at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Accepting className props is also an anti-pattern that we don't want to encourage.

And what should I do then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If article defines its own className in future, it will work when the parents don't pass in a className but will break when the parents do.

We can merge classes with classnames lib, right? Why is that bad? I agree with passing rest props, but why can't extract className if all CSS classes are merged later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used a different approach, I hope it will be good for you 83eeafc

Copy link
Contributor

Choose a reason for hiding this comment

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

We can merge classes with classnames lib, right? Why is that bad?

Which class get priority? The component's classes or the user's classes? Either approach is bad as it leads to unpredictable behavior. In this scenario:

.user-class { padding: 0; }
.component-class { padding: 12px; }

Both classes affect padding and again this makes the final result dependent on CSS ordering. Imagine the user added background-color: red to .user-class and in a future release we add background-color: orange to .component-class, it could break the user's CSS. Also, since we use webpack with code splitting, the CSS loading order is hard to reason about and can lead to obscure bugs.

The only way is to not allow any merging of CSS classes. This is our practice for Facebook components. For common properties that people like to override, we allow passing in of margin/padding props. What you've done here is acceptable as we're still in control.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification, in this case, the situation is somewhat different, since we are dealing with an internal component, I mean, an end user can set own CSS class only if component will be swizzled, initially I did not take this fact into account.

Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

This is better, thanks!

@@ -21,16 +21,14 @@ function BlogListPage(props) {
<div className="col col--8 col--offset-2">
{items.map(
({content: BlogPostContent, metadata: blogPostMetadata}) => (
<div
Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, the <div> is there so that we can add margin. If we don't need to add margin of course not having a div is better.

@yangshun yangshun merged commit dec9c12 into facebook:master Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: polish This PR adds a very minor behavior improvement that users will enjoy.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants