-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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(docusaurus-init): cleanup #4571
refactor(docusaurus-init): cleanup #4571
Conversation
[V2] Built without sensitive environment variables with commit ebe0a70 |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-4571--docusaurus-2.netlify.app/ |
Can you squash the last commit |
@Foxeye-Rinx I could, but I was under the assumption the commits would get squashed upon merge. I'll do it now either way, though. |
refactor(docusaurus-init): switch chalk -> colorette refactor(docusaurus-init): cleanup main script chore(docusaurus-init): reformat readme refactor(docusaurus-init/templates): cleanup bootstrap refactor(docusaurus-init/templates): cleanup facebook style(docusaurus-init): apply lint
bfd94bc
to
ebe0a70
Compare
Hi and thanks for your contribution. I'm sorry but I'm going to close this PR for a few reasons:
If you want to contribute by refactoring, the best way could be to first discuss about the refactors you plan to do, or contact me on discord to know if the refactors you plan to do are welcome |
@@ -52,11 +53,11 @@ function Feature({imageUrl, title, description}) { | |||
const imgUrl = useBaseUrl(imageUrl); | |||
return ( | |||
<div className={clsx('col col--4', styles.feature)}> | |||
{imgUrl && ( | |||
<If condition={imgUrl}> |
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.
this is a React anti-pattern and not somthing we'll add
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 you don't want to make code more readable that way, optional chaining should still be used in other places. features && features.length > 0
is clunky and unnecessary.
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.
We definitively don't want to use the <If>
antipattern,
At the time this code was written, optional chaining did not exist, and this code is not updated too frequently. I'm not against using optional chaining now, but keep in mind that features && features.length > 0
is not particularly clunky. In fact, for a non-frontend dev, it might be easier to understand compared to optional chaining. Keep in mind not all Docusaurus users are frontend devs, some are coming from other languages, are not aware of optional chaining, or are from academics background, and they don't care much about using top-notch ES features
@@ -7,27 +7,25 @@ | |||
* LICENSE file in the root directory of this source tree. | |||
*/ | |||
|
|||
const chalk = require('chalk'); | |||
const color = require('colorette'); |
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.
Why do we want colorette instead of chalk? how can you be sure that this change has no impact for all users and all OS? Why do we want this change only in one package instead of all of them?
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.
Colorette is faster and, well, it's a better package. It doesn't make use of weird prototyping, is solely functional, and if anything provides more support with NO_COLOR
(I'm not sure if Chalk does, but they don't mention 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.
Colorette is faster and, well, it's a better package.
You'll have to justify your args with benchmarks and external links to back up your claims, and also explain how changing from chalk to colorette is a seamless change that is not risky. If you don't do this, I'll have to do this myself, so you put the work on me. The hard work is not to change an import, it is to assess the risk of changing that import. Everyone can change a package import and then leave when things are on fire.
If something breaks for some reason after this refactor, will you be there to fix the issues reported?
Will we live with using both colorette + chalk in the monorepo for a while or do you plan to migrate everything to colorette soon? Is there a risk that we end up with 2 libs for many years if you don't send another PR? I'd prefer to make the change atomic to the whole codebase at once if we agree that we should use colorette.
@@ -19,7 +19,8 @@ | |||
"@mdx-js/react": "^1.5.8", | |||
"classnames": "^2.2.6", | |||
"react": "^17.0.1", | |||
"react-dom": "^17.0.1" | |||
"react-dom": "^17.0.1", |
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.
theme bootstrap is unmaintained currently, we'll make it production ready later but it's not worth to update it atm
@@ -22,8 +23,8 @@ function hasYarn(): boolean { | |||
} | |||
} | |||
|
|||
function isValidGitRepoUrl(gitRepoUrl: string): boolean { |
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 don't think there is a significant perf issue in docusaurus-init. Do we really need to refactor this file in subtle ways (like changing Regexes), particularly when this part of the codebase has not a strong code coverage?
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 could still perform better and if it can, why not go for it? Plus, the code does the same thing, there is no need for additional testing as it is synonymous but a cleaner and more performant version. Code quality should be a priority.
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 against these changes, but then please add unit tests.
Plus, the code does the same thing
That's what it looks like (unless there is a hidden typo, which is always a possibility with Regexes) but any change without a test ends up being a risky change for me.
Code quality and cleanliness is incredibly valuable.
Many, many, many ways. Boolean expression optimization, use of
That was a lot of the intention of the cleanup.
If a relatively small single-package cleanup is too much for a single PR, I'm not entirely sure how Facebook manages to work at any efficient pace, but congratulations to you all for pulling that off.
That's what PR discussions and code review is for - I can refactor, discuss the changes I made, and then alter it depending on the achieved conclusion prior to merge. Better for everyone. |
Agree
I see some of these are decent micro-optimizations to performance problems we don't have in the first place, in a critical flow of the Docusaurus experience that does not change often and is currently not covered by tests. Is this really necessary to do these changes? If we do, shouldn't we add tests at the same time to ensure the behavior before/after is the same?
That does not feel very constructive.
Then let's do that and move on: you have my review, feel free to handle it or not. Just to help you understand better my perspective:
Refactors are welcome, but please:
Examples PRs:
Those 3 PRs would be much easier to merge for me |
Motivation
(Write your motivation here.)
Have you read the Contributing Guidelines on pull requests?
I have followed all contributing guidelines and signed the CLA accordingly.
Test Plan
The primary changes made are not functionality, but rather performance
improvements and code refactoring. I have verified these changes pass all
available tests and both used the refactored CLI myself and used
yarn start
to ensure the site templates build and render correctly. This should require no
additional
jest
tests.Related PRs
There is no changed functionality involved with this PR, merely improvements
over existing functionality. I am not currently aware of PRs that involve the
aforementioned functionality but I will link to them if I find them.