Skip to content

Commit

Permalink
Fix: #10548 AtD / Gutenberg: request is made to AtD when module is de…
Browse files Browse the repository at this point in the history
…activated (#10566)

Fixes #10548
Fixes #10495
Fixes #10558

#### Changes proposed in this Pull Request:
* Instead of using `get_initial_state()` to shorthand how we get module activation data for block visibility this PR manually builds the needed data.
* `get_initial_state()` calls `get_modules` from `Jetpack_Core_API_Module_List_Endpoint` which doesn't respect module activation and [includes modules files](https://github.com/Automattic/jetpack/blame/496bebd5b1890666afe4fc79f52fd94353d88539/_inc/lib/class.core-rest-api-endpoints.php#L2813) which enqueues JS files ¯\_(ツ)_/¯ 

#### Testing instructions:
* Follow the steps in #10548
* Ideally you wont see any JS errors

#### Proposed changelog entry for your changes:
* Fixes an issue where deactivating ATD causes the post editor to throw JS errors
  • Loading branch information
lezama authored and jeherve committed Nov 9, 2018
1 parent f98eef0 commit 2c9ac3c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,23 @@ public static function enqueue_block_editor_assets() {
plugins_url( '_inc/blocks/', JETPACK__PLUGIN_FILE )
);

$jp_react_page = new Jetpack_React_Page();
wp_localize_script(
'jetpack-blocks-editor',
'Jetpack_Initial_State',
$jp_react_page->get_initial_state()
array(
'getModules' => array(
'markdown' => array(
'name' => 'markdown',
'activated' => Jetpack::is_module_active( 'markdown' ),
'override' => Jetpack_Modules_Overrides::instance()->get_module_override( 'markdown' )
),
'related-posts' => array(
'name' => 'related-posts',
'activated' => Jetpack::is_module_active( 'related-posts' ),
'override' => Jetpack_Modules_Overrides::instance()->get_module_override( 'related-posts' )
)
)
)
);

Jetpack::setup_wp_i18n_locale_data();
Expand Down

0 comments on commit 2c9ac3c

Please sign in to comment.