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

Fix error with Heartbeat settings in edit-form-blocks.php #7429

Closed

Conversation

azaozz
Copy link
Contributor

@azaozz azaozz commented Sep 24, 2024

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.

Copy link

github-actions bot commented Sep 24, 2024

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props azaozz, peterwilsoncc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a 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' );

}
} );
}',
'before'
Copy link
Contributor

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.

/**
* Contains the Heartbeat API.
*
* @namespace wp.heartbeat
* @type {Heartbeat}
*/
window.wp.heartbeat = new Heartbeat();

@azaozz
Copy link
Contributor Author

azaozz commented Sep 25, 2024

Are you able to add dom ready as a dependency to the heartbeat

Sure.

Changing this to after will negate the need to check heartbeat is defined

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 window.wp and window.wp.heartbeat will be defined in all cases. Fixing..

heartbeat.js depends on it already
@azaozz
Copy link
Contributor Author

azaozz commented Sep 25, 2024

Simplified and switched to using jQuery for DOM ready. Heartbeat depends on it already, seems no point in adding another dependency.

Copy link
Contributor

@peterwilsoncc peterwilsoncc left a 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. ;)

@azaozz
Copy link
Contributor Author

azaozz commented Sep 25, 2024

@azaozz azaozz closed this Sep 25, 2024
@azaozz azaozz deleted the fix/heartbeat-settings-block-editor branch September 25, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants