Skip to content

Jetpack Gutenberg Blocks only load assets as required - #10397

Closed
enejb wants to merge 2 commits into
masterfrom
try/jetpack-gutenber-only-load-assets-as-required
Closed

enejb wants to merge 2 commits into
masterfrom
try/jetpack-gutenber-only-load-assets-as-required

Conversation

@enejb

@enejb enejb commented Oct 24, 2018

Copy link
Copy Markdown
Member

This PR tries to load

Only the required front end assets when the block is being rendered.

It also removes the CDN part since we assume that part would be taken care of by the CDN project.
cc: @zinigor (let me know if this is not the case)

This PR implement a new jetpack_register_block function. Which helps Jetpack have a better understand what blocks are supported and active. Different modules could be disabled. This information could then also be used in the editor to show/hide the blocks there as well.

To test

Add the tile block and maker sure that the assests are only loaded on the front end (css and js) related to this.

This is the required wp-calypso branch. Automattic/wp-calypso#28066 that needs to be used to build the bundle.

@enejb
enejb requested review from a team, gititon, jeffersonrabb, simison and sirreal October 24, 2018 21:48
@enejb enejb added [Status] Needs Review This PR is ready for review. [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Oct 24, 2018
@enejb enejb added this to the 6.7 milestone Oct 24, 2018
@enejb enejb changed the title Try/jetpack gutenber only load assets as required Jetpack Gutenberg Blocks only load assets as required Oct 24, 2018
@jeherve
jeherve force-pushed the try/jetpack-gutenber-only-load-assets-as-required branch from a37b3fa to 5e57031 Compare October 25, 2018 15:27
@jetpackbot

Copy link
Copy Markdown
Collaborator
Warnings
⚠️

"Testing instructions" are missing for this PR. Please add some

⚠️

"Proposed changelog entry" is missing for this PR. Please include any meaningful changes

This is automated check which relies on PULL_REQUEST_TEMPLATE.We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS

@jeherve

jeherve commented Oct 25, 2018 •

Copy link
Copy Markdown
Member

I rebased to avoid conflicts after 8f9c371, and so Travis tests can complete and we can get Jurassic Ninja sites for testing.

JN test

@simison

simison commented Oct 25, 2018 •

Copy link
Copy Markdown
Member

You might want to consider removing CDN parts first in a separate PR to make reviewing this one easier.

CDN parts were almost removed earlier already, see: #10299

@simison

simison commented Oct 25, 2018

Copy link
Copy Markdown
Member

Remember to update docs/guides/gutenberg-blocks.md accordingly.

@simison
simison requested a review from a team October 25, 2018 15:40
@jeffersonrabb

Copy link
Copy Markdown
Contributor

On the frontend, I'm not seeing the Tiled Gallery view script load and the block doesn't appear. At first glance it looks like this may be because load_assets_as_required is called only from within enqueue_block_editor_assets, which wouldn't be called in the frontend.

@kraftbj kraftbj added [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. and removed [Status] Needs Review This PR is ready for review. labels Oct 25, 2018
enejb added a commit that referenced this pull request Oct 25, 2018
@enejb

enejb commented Oct 25, 2018

Copy link
Copy Markdown
Member Author

Thanks for all the reviews here. I am closing this in favor of #10405

@enejb enejb closed this Oct 25, 2018
@enejb
enejb deleted the try/jetpack-gutenber-only-load-assets-as-required branch October 25, 2018 21:50
@enejb

enejb commented Oct 25, 2018 •

Copy link
Copy Markdown
Member Author

@jeffersonrabb

On the frontend, I'm not seeing the Tiled Gallery view script load and the block doesn't appear. At first glance it looks like this may be because load_assets_as_required is called only from within enqueue_block_editor_assets, which wouldn't be called in the frontend.

The Tile Gallery front end assets should be required in jetpack_tiled_gallery_load_assets function call.

I have re implemented this PR in #10405 it is a more consise and only changes the relevant parts.

enejb added a commit that referenced this pull request Oct 30, 2018
enejb added a commit that referenced this pull request Oct 30, 2018
* Gutenblock: Add the frontend code only if the block is being called.

This Removed the loading of the front end code that comes as a bundle of all the files.
And make sure that it loads only the front end code that is needed when the block is going to be displayed.

* Register the tiled-galley code block

This lets us register the tiled gallery code to be loaded on the front end only

* Changes applied to #10397 by gititon

Props @gititon.

* Minor bug fix

* fix linting

* missing !

* Added code dock blocks and set the default priority

* Fixed the RTL issue

* Minor doc block fixes

* Gutenberg: fix all linter errors in file.

We'll rely on those functions a lot in the next few months, the different comments should help us get all
the info we need in our IDEs.
It also acts as a good example for other folks who may be interested in how Jetpack adds support for its
blocks.

* Language extraction: account for blocks in sub-directories.

@see #10405 (comment)

* Sanitize the type.
* Sanitize the type again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants