-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Blocks: Consider moving UI components out of /blocks
folder
#2788
Comments
How do we define reusable? The components within |
Not sure I agree with these changes, some of these components have strong dependencies and I don't think we should introduce these strong dependencies in the For example:
The inspector controls could be considered UI components though |
I noticed that my concerns will be partially addressed in #2795, where Now let me elaborate more on the second part. We use all those relative paths everywhere, which is fine, but maybe we could borrow some patterns from Facebook and their custom module system called “Haste”. I recommend reading this part of React docs. They never use relative paths when importing. They explain that it makes it easy to move files to different folders and import them without worrying about relative paths. If you don't find it as easy to apply to Gutenberg, I'm happy to close this issue. |
Re: Haste. Hmm, global uniqueness seems quite restrictive, though I assume in an application the size of Facebook, it would be fairly evident if this was an issue to scale, so clearly they've found some success. I do feel it would be quite confusing for the uninitiated, and Facebook themselves notes in the documentation you link that they may migrate to a more standard CommonJS / ES Modules for alignment with the community. One of the original reasons for using relative paths was to help distinguish between external, "WordPress", and internal dependencies by path. Previously we did not have the |
Yes, I like this idea a lot. This is what seemed like a perfect choice when I saw imports using
I only shared Facebook example to give a better context. I don't think we should introduce such restrictive rules. I like a lot what you initially introduced in #386. A full local import path also gives a bit better idea what are you really importing and makes it easy to move files to a different folder as you don't need to update import statements. |
It looks like it is as easy as including this Webpack plugin: |
The relative paths don't bother me at all, in fact, sometimes I find them useful in distinguishing misplaced dependencies (between internal, WordPress and external deps). The most important thing is having a failed build when importing a wrong path. I have no strong opinion on dropping the relative paths or not |
Closing this one for now. I will open PR if I find it more important 😄 |
Issue Overview
At the moment
/blocks
folder contains lots of smaller reusable components that are shared between many existing blocks. I found it very confusing where trying to locate one of such existing components. I expected to find it inside/components
folder. If we would opt for moving those shared components to/components
folder we could also fix this strange relative path that repeats in all blocks. It's not an issue at the moment, but as soon we will want to move one of the blocks outside of Gutenberg it might become an issue. It simply ties location of those components with the blocks forever. It also makes it harder to reuse those components in external blocks that we want to supper in the near future. I would like to propose to move those components inside/components
folder and take advantage of@wordpress/components
alias.Current Behavior
Example file: https://github.com/WordPress/gutenberg/blob/da364e8a69ba288ac5cf154a9d4f97c7957faa34/blocks/library/gallery/block.js.
Possible Solution
The text was updated successfully, but these errors were encountered: