-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix error with Heartbeat settings in edit-form-blocks.php #7429
Fix error with Heartbeat settings in edit-form-blocks.php #7429
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @azaozz, this fixes the issue.
As a minor change request: Are you able to add dom ready as a dependency to the heartbeat to ensure future changes to the order of operations and/or block editor script dependencies don't result in the interval going back to 15 seconds? You'll be able to remove the test domReady
is defined too.
As some rubber ducking on an alternative: could it be worth using a null
source to ensure the dependency changes only affect the block editor. Something like:
// Set Heartbeat interval to 10 seconds, used to refresh post locks.
wp_register_script( 'wp-heartbeat-block-editor-interval', false, array( 'heartbeat', 'wp-dom-ready' ), false, array( 'in_footer' => 'true' ) );
wp_add_inline_script(
'wp-heartbeat-block-editor-interval',
'window.wp.domReady( function() {
if ( window.wp.heartbeat ) {
window.wp.heartbeat.interval( 10 );
}
} );',
'after'
);
wp_enqueue_script( 'wp-heartbeat-block-editor-interval' );
src/wp-admin/edit-form-blocks.php
Outdated
} | ||
} ); | ||
}', | ||
'before' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this to after
will negate the need to check heartbeat is defined, the script defines it as the script loads.
wordpress-develop/src/js/_enqueues/wp/heartbeat.js
Lines 892 to 898 in 4712210
/** | |
* Contains the Heartbeat API. | |
* | |
* @namespace wp.heartbeat | |
* @type {Heartbeat} | |
*/ | |
window.wp.heartbeat = new Heartbeat(); |
Sure.
Right. Seems the before/after wouldn't make much difference as they will not be outputted if heartbeat.js is not outputted. But you're right, this patch/PR is way too cautious, was mostly to confirm it works now. It can be written better as both |
heartbeat.js depends on it already
Simplified and switched to using jQuery for DOM ready. Heartbeat depends on it already, seems no point in adding another dependency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks boss, looks good to me.
seems no point in adding another dependency.
Yea, that seems sensible. ;)
Committed: https://core.trac.wordpress.org/changeset/59092. |
Seems this should be running on DOM ready.
Trac ticket: https://core.trac.wordpress.org/ticket/61960
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.