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

Blocks: load each block from a separate file. #11286

Closed
wants to merge 3 commits into from

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Feb 6, 2019

Changes proposed in this Pull Request:

As we work to add several new modules, the existing module/blocks.php is updated quite often. It causes a few issues:

  • The file keeps getting longer and longer.
  • The longer the file, the longer it takes to skim through it.
  • Everyone working on that file ends up having to rebase frequently because we are merging changes to that file often.
  • Keeping the file in sync with WordPress.com can be more work if someone does not commit their matching WordPress.com diff immediately after merging a Jetpack PR.

Splitting things into different files makes things easier to maintain for everyone.

Internal reference: pafL3P-io-p2

Testing instructions:

  • Go to Posts > Add New
  • Do you see, and can you use all blocks?
  • Yay.

Proposed changelog entry for your changes:

  • None.

As we work to add several new modules, the existing module/blocks.php is updated quite often. It causes
a few issues:

- The file keeps getting longer and longer.
- The longer the file, the longer it takes to skim through it.
- Everyone working on that file ends up having to rebase frequently because we are merging changes to
that file often.
- Keeping the file in sync with WordPress.com can be more work if someone does not commit their matching
WordPress.com diff immediately after merging a Jetpack PR.

Splitting things into different files makes things easier to maintain for everyone.
@jeherve jeherve added [Status] Needs Review To request a review from Crew. Label will be renamed soon. [Type] Janitorial [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Block] Map [Block] Slideshow [Block] GIF [Block] Business Hours [Block] Contact Info labels Feb 6, 2019
@jeherve jeherve added this to the 7.1 milestone Feb 6, 2019
@jeherve jeherve self-assigned this Feb 6, 2019
@jeherve jeherve requested a review from a team as a code owner February 6, 2019 10:15
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello jeherve! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D23984-code before merging this PR. Thank you!

@jetpackbot
Copy link

jetpackbot commented Feb 6, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: March 5, 2019.
Scheduled code freeze: February 26, 2019

Generated by 🚫 dangerJS against 3f6b242

@jeherve jeherve added [Status] In Progress and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Feb 6, 2019
modules/blocks.php Outdated Show resolved Hide resolved
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D23984-code has been updated.

@jeherve jeherve added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels Feb 6, 2019
@jeherve jeherve requested review from a team February 6, 2019 10:57
@sirreal
Copy link
Member

sirreal commented Feb 6, 2019

Should these generic blocks even live under modules, or could they move up a level?

Asking the dumb question in case you didn't consider it. I understand there may be reason to keep it where it is.

This file is unusual, and is not an actual module as such.

This always concerned me 🙂

@jeherve
Copy link
Member Author

jeherve commented Feb 6, 2019

I did not consider it, so thanks for asking. I don't have a good answer here. Why not I suppose? I don't really have a preference here, so happy to change that if necessary. Just say the word :)

@ockham
Copy link
Contributor

ockham commented Feb 6, 2019

Should these generic blocks even live under modules, or could they move up a level?

It's even weirder on WP.com where I think the modules dir was only created to hold blocks.php. All other JP modules map to subdirs in mu-plugins and admin-plugins IIRC.

I'm all for moving things elsewhere, but I'm not sure what would be the best location on WP.com -- we should probably figure that out.

@ockham
Copy link
Contributor

ockham commented Feb 6, 2019

BTW thanks for this. Updating modules/blocks.php has been kind of annoying during development of #11212.

(I mean it will be quite annoying to do it again if this one lands before, but at least things will be easier in the long run 😅 )

See #11286 (comment)

I also took the opportunity to get rid of the blocks file entirely.
It is not needed anymore, we can now move the loading of the blocks to the actual Gutenberg class.
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D23984-code has been updated.

@jeherve
Copy link
Member Author

jeherve commented Feb 6, 2019

@sirreal @ockham Thank you both for the feedback. I moved things around in 3f6b242.

  • The blocks now live in /blocks at the root of the plugin.
  • We don't really need modules/blocks.php anymore. I moved the loading of all the blocks inside the Gutenberg class, to keep everything in one place.

@jeherve
Copy link
Member Author

jeherve commented Feb 6, 2019

It's even weirder on WP.com where I think the modules dir was only created to hold blocks.php. All other JP modules map to subdirs in mu-plugins and admin-plugins IIRC.

I'm all for moving things elsewhere, but I'm not sure what would be the best location on WP.com -- we should probably figure that out.

I placed them in wp-content/mu-plugins/jetpack/blocks in my diff so far because it makes syncing easier (I don't have to worry about setting 2 different paths in load_independent_blocks), but I am happy to reconsider.

@lezama
Copy link
Contributor

lezama commented Feb 6, 2019

Thanks for working on this @jeherve!

@jeherve
Copy link
Member Author

jeherve commented Feb 7, 2019

Since we've talked about the blocks' location, here is how I would personally envision the blocks's file structure in the future:

  1. _inc/client/blocks for the blocks’s JSX (once we move those files from Calypso to Jetpack)
  2. _inc/blocks for the built blocks (it is already like that today, those are the files that get shipped to customers). This could also be changed to _inc/build/blocks to match the other things we build within Jetpack.
  3. /blocks for the blocks’ PHP files (those live in a single modules/blocks.php today, and that is what this PR aims to change)

@simison
Copy link
Member

simison commented Feb 7, 2019

Not saying we should always follow core's patterns but just for the record and awereness:

https://github.com/WordPress/gutenberg/tree/8ba4a209b4b1a1bf6e3037d3dea86392d03c2c44/packages/block-library/src

  • a folder per block under block-library root folder
  • PHP & JS related to each block under same folder
  • Root folder has package.json (and blocks are under src) as Gutenberg is a monorepo and they publish these folders to NPM.

@jeherve
Copy link
Member Author

jeherve commented Feb 7, 2019

@simison I like it! That actually makes a lot of sense, especially in the context of publishing every block to npm separately.

On our end, that structure would probably be easier to understand for new contributors once we bring the blocks's JSX to Jetpack.

I have 2 questions about this approach:

  • Where would we put the built blocks' code in that scenario?
  • Would it be confusing for blocks like Markdown or Contact Form, where the blocks' PHP lives within the module? Would one expect the block's PHP code in there, since that's how it works for independent blocks?

@simison
Copy link
Member

simison commented Feb 7, 2019

Great questions!

Where would we put the built blocks' code in that scenario?

I would probably try to re-align with the rest of Jetpack and:

  • Build files in_inc/build folder (so _inc/build/gutenberg-extensions?)
  • Have both, production .min.js and development .js files shipped in Jetpack just like we do for the rest of the assets so that folks can debug without re-compiling everything and switch between the two using SCRIPT_DEBUG constant.

I recognize these are not something we can do now but it's good to envision a bit further into the future at this point.

Would it be confusing for blocks like Markdown or Contact Form, where the blocks' PHP lives within the module? Would one expect the block's PHP code in there, since that's how it works for independent blocks?

I think it's okay; that's basically how core blocks work, too. They rely on APIs and functionality from other files (think search block, recent posts block, or upcoming comments block). I'd expect there to be at least one PHP file for each block where we'd actually define at least dependencies for the block so that at least those would be in the same place with JS sources.

I would also take the chance and rename the root folder to something else than blocks since we technically have all sorts of Gutenberg integrations, not just blocks. But I recognise "blocks" has become common language for these already so I don't feel strongly about this.

How does that sound?

@simison
Copy link
Member

simison commented Feb 7, 2019

_inc/build/gutenberg-extensions

On 2nd thought, we might also want to eventually phase out "gutenberg" term (and use "block editor" instead) so worth considering if we could avoid introducing it. Core has been doing similar changes recently.

So _inc/build/block-editor ?

@enejb
Copy link
Member

enejb commented Feb 7, 2019

Just some backround info as to why I placed blocks into /modules/blocks.php

It was mostly done for consistency.
We currently have module for shortcodes that lives inside there. /modules/shortcodes/* and /modules/shortcodes.php So it made sense to me for blocks to also live there that to be the same.

There is also some precedent on code that isn't exactly a module to live in that directory.

So my suggestion is to not have a special folded called blocks in jetpack. but to place the blocks code back in modules/blocks :)

@sirreal
Copy link
Member

sirreal commented Feb 8, 2019

I haven't tested, but this seems to me like a nice change that will benefit developers. I like to know where things should go and understand why 🙂

Should all this live in one file? It's pretty clear to me that it should not. The whopping 7000+ line class.jetpack.php is a great example of when that pattern is left to run wild. I'm glad we're getting ahead of this one.

Should we call it blocks? 🤷‍♂️ I'm not sure. At this point it all seems to be all blocks. Seems descriptive at this time, that may change, naming things is hard. Good enough for now.

Should it live under modules? 🤷‍♂️ What's a module? Jetpack modules seem to be a specific thing with some expected behavior. The fact that it's strange enough that we need to mention in the header "Hey, this isn't actually a module" indicates to me that the location should raise some red flags.

Maybe blocks are modules? Why not? That's the paradigm for additional functionality that Jetpack has. Why not just make each block a module? It's probably just overhead, but these are the kind of lines we can draw that helps me to work effectively. If the contract with Jetpack is that it provides a core that modules can extend, maybe that's exactly what we should be doing.

This has gotten a bit philosophical so I'll bring it back home. I'm in favor of this change, but @Automattic/jetpack-crew should have the final say. At the end of the day, I don't care too much exactly where the files live, every decision has tradeoffs. I do think it's important we reason about why we make the decisions we do and consider alternatives.

@jeherve
Copy link
Member Author

jeherve commented Feb 8, 2019

@dereksmart Could you weigh in on this maybe? Thank you!

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

I haven't had time to test this, but I wanted to manifest my support of the general direction taken here.

I'll reference my more rambling thoughts with greater detail in another comment (#11286 (comment))

@jeherve
Copy link
Member Author

jeherve commented Feb 8, 2019

Closing in favor of #11312, as the rebase was a nightmare :(

@jeherve jeherve closed this Feb 8, 2019
@simison simison deleted the update/block-loading-split branch February 9, 2019 12:52
@kraftbj kraftbj removed the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants