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

Enqueue editor and block scripts only when necessary #8

Open
bobbingwide opened this issue Feb 27, 2018 · 2 comments
Open

Enqueue editor and block scripts only when necessary #8

bobbingwide opened this issue Feb 27, 2018 · 2 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Feb 27, 2018

With the current version of the new block editor plugin there have been issues with plugins enqueueing scripts which then cause failures in parts of the admin interface.

Noted so far in issue 4678,

  • classic editor fails to load
  • Text widget fails to load

These were being addressed in PR 4693 but this has been closed due to technical difficulties.

We need to ensure that we are responding correctly to the action hooks by taking into account the context. The table below shows the scripts we should enqueue in response to the action hooks that are invoked. The ; prefixes indicates that the hook is nested in the hook in the preceding row.
The Y indicates if the hook is invoked. Note that replace_editor is a filter.

Hook Front end Block editor Classic-editor Admin
wp_head Y
; wp_enqueue_scripts Y
; ; enqueue_block_assets Y - frontend_scripts
replace_editor Y Y
; admin_enqueue_scripts Y
; ; enqueue_block_editor_assets Y - editor_scripts
admin_enqueue_scripts Y Y

This table relies on Gutenberg only calling do_action for these hooks when it's appropriate.
It assumes the fix for 4678 has been implemented.

The Block editor is invoked for Add new ( postnew.php ) and Edit ( post.php )
except when the classic-editor query parameter is set; in which case the Classic Editor is used.

Responding to action hooks is one way that a plugin/theme can specify which scripts to enqueue. Another method is through the register_block API.
Investigate how this works then adjust the next paragraph accordingly.

Gutenberg doesn't really help us to determine whether or not we need to enqueue the frontend scripts ( and styles ). It assumes that they'll be needed.... which probably won't be the case for the majority of front end displays until users start using dynamic blocks wholesale.

@bobbingwide bobbingwide added bug Something isn't working enhancement New feature or request labels Feb 27, 2018
@bobbingwide bobbingwide self-assigned this Feb 27, 2018
@bobbingwide
Copy link
Owner Author

We also need to cater for the fact that the Gutenberg plugin may not be installed / activated.

@bobbingwide
Copy link
Owner Author

Responding to action hooks is one way that a plugin/theme can specify which scripts to enqueue.
Another method is through the register_block_type API.
Investigate how this works then adjust the next paragraph accordingly.

For the first part of this we'll change the styling of the Contact form block and then alter the way that it's enqueued, using register_block_type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant