Skip to content

Gutenberg RTC: Support HTTP polling provider#47485

Merged
arthur791004 merged 3 commits intotrunkfrom
feat/gb-rtc-default-provider
Mar 9, 2026
Merged

Gutenberg RTC: Support HTTP polling provider#47485
arthur791004 merged 3 commits intotrunkfrom
feat/gb-rtc-default-provider

Conversation

@arthur791004
Copy link
Contributor

@arthur791004 arthur791004 commented Mar 6, 2026

Related DOTCOM-16238

Proposed changes:

  • Support HTTP polling provider as we want to enable it for free sites and limit 2 collaborators

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Apply changes to your sandbox
  • Add following filters to mu-plugins/0-sandbox.php
    add_filter( 'wpcom_is_gutenberg_rtc_enabled', '__return_true' );
    
    add_filter( 'wpcom_gutenberg_rtc_providers', function() {
      return [ 'http-polling' ];
    } );
  • Go to edit a page/post
  • Check the network request
  • Ensure it polls /wp-sync/v1/sites/:site/updates endpoint

Changelog

  • Generate changelog entries for this PR (using AI).

Copilot AI review requested due to automatic review settings March 6, 2026 13:59
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (WordPress.com Site Helper), and enable the feat/gb-rtc-default-provider branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack-mu-wpcom-plugin feat/gb-rtc-default-provider

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Mu Wpcom plugin:

  • Next scheduled release: WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2)

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Wpcomsh plugin:

  • Next scheduled release: Atomic deploys happen twice daily on weekdays (p9o2xV-2EN-p2)

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Mar 6, 2026
@arthur791004 arthur791004 self-assigned this Mar 6, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for using Gutenberg Real-Time Collaboration (RTC) with the default HTTP polling provider by avoiding injecting the Jetpack MU script when it would unnecessarily override Gutenberg’s default provider behavior.

Changes:

  • Detect when the only configured RTC provider is http-polling and skip enqueuing/injecting the gutenberg-rtc asset + inline config in that case.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jp-launch-control
Copy link

jp-launch-control bot commented Mar 6, 2026

Code Coverage Summary

Coverage changed in 2 files.

File Coverage Δ% Δ Uncovered
projects/packages/jetpack-mu-wpcom/src/utils.php 6/81 (7.41%) -0.59% 6 💔
projects/packages/jetpack-mu-wpcom/src/features/gutenberg-rtc/gutenberg-rtc.php 41/45 (91.11%) 42.72% -12 💚

Full summary · PHP report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

@github-actions github-actions bot added [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh labels Mar 6, 2026
Copilot AI review requested due to automatic review settings March 9, 2026 03:35
@arthur791004 arthur791004 force-pushed the feat/gb-rtc-default-provider branch from aba34f0 to 97826d5 Compare March 9, 2026 03:35
@arthur791004 arthur791004 added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Mar 9, 2026
@github-actions github-actions bot 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 Mar 9, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@arthur791004 arthur791004 added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Mar 9, 2026
@github-actions github-actions bot 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 Mar 9, 2026
@arthur791004 arthur791004 added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Mar 9, 2026
@github-actions github-actions bot 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 Mar 9, 2026
@arthur791004 arthur791004 force-pushed the feat/gb-rtc-default-provider branch from 97826d5 to 5f59c52 Compare March 9, 2026 04:49
@arthur791004 arthur791004 removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Mar 9, 2026
@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Mar 9, 2026
Copilot AI review requested due to automatic review settings March 9, 2026 05:08
@arthur791004 arthur791004 force-pushed the feat/gb-rtc-default-provider branch from 5f59c52 to 2a02e4a Compare March 9, 2026 05:08
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

projects/packages/jetpack-mu-wpcom/src/features/gutenberg-rtc/gutenberg-rtc.php:65

  • wpcom_enqueue_gutenberg_rtc_assets() computes $providers once, but then calls wpcom_get_gutenberg_rtc_providers() again when building the inline data. Since this runs filters, the second call can be inconsistent (or expensive) and makes behavior dependent on filter side effects. Reuse the already-computed $providers when encoding the inline script.
	$providers = wpcom_get_gutenberg_rtc_providers();

	// If HTTP polling (Gutenberg’s built-in default provider when this script isn’t enqueued)
	// is the only provider being used, then we don’t need to inject any assets since that’s
	// already the default behavior.
	if ( count( $providers ) === 1 && in_array( 'http-polling', $providers, true ) ) {
		return;
	}

	$handle = jetpack_mu_wpcom_enqueue_assets( 'gutenberg-rtc', array( 'js' ) );

	$data = wp_json_encode(
		array(
			'providers' => wpcom_get_gutenberg_rtc_providers(),
		),
		JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +207 to +219
public function test_wpcom_enqueue_gutenberg_rtc_assets_skips_http_polling_only() {
add_filter( 'wpcom_is_gutenberg_rtc_enabled', '__return_true' );
add_filter(
'wpcom_gutenberg_rtc_providers',
function () {
return array( 'http-polling' );
}
);

wpcom_enqueue_gutenberg_rtc_assets();

$this->assertFalse( wp_script_is( 'jetpack-mu-wpcom-gutenberg-rtc', 'enqueued' ) );
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These enqueue-related tests can be order-dependent because the global script registry persists across tests. If another test enqueues jetpack-mu-wpcom-gutenberg-rtc first, test_wpcom_enqueue_gutenberg_rtc_assets_skips_http_polling_only() may fail even though the code is correct. Reset $wp_scripts (as other tests in this package do) or explicitly dequeue/deregister the script in tear_down() before asserting enqueue state.

Copilot uses AI. Check for mistakes.
@arthur791004 arthur791004 force-pushed the feat/gb-rtc-default-provider branch from 2a02e4a to cde0de9 Compare March 9, 2026 05:20
@arthur791004 arthur791004 added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label Mar 9, 2026
Copilot AI review requested due to automatic review settings March 9, 2026 05:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

Copilot AI review requested due to automatic review settings March 9, 2026 05:37
@arthur791004 arthur791004 force-pushed the feat/gb-rtc-default-provider branch from 3932e7c to a0c2ee7 Compare March 9, 2026 05:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

projects/packages/jetpack-mu-wpcom/tests/php/features/gutenberg-rtc/Gutenberg_RTC_Test.php:75

  • Test isolation: storing/restoring $wp_scripts/$wp_styles without resetting them means any enqueued/registered scripts from a test can leak into later tests (the stored value is the same object reference). In this repo other tests explicitly reset the script registry (e.g. by setting $wp_scripts = null or creating a new WP_Scripts) to avoid flakiness. Consider resetting $wp_scripts/$wp_styles to a clean state in set_up (after saving originals), so each test starts with an empty registry, then restore originals in tear_down.
	public function set_up(): void {
		parent::set_up();
		global $wp_settings_fields, $wp_scripts, $wp_styles;
		$this->original_wp_settings_fields = $wp_settings_fields;
		$this->original_wp_scripts         = $wp_scripts;
		$this->original_wp_styles          = $wp_styles;
	}

	/**
	 * Clean up filters and restore global state after each test.
	 */
	public function tear_down(): void {
		global $wp_settings_fields, $wp_scripts, $wp_styles;
		$wp_settings_fields = $this->original_wp_settings_fields; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		$wp_scripts         = $this->original_wp_scripts; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		$wp_styles          = $this->original_wp_styles; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
		remove_all_filters( 'wpcom_is_gutenberg_rtc_enabled' );
		remove_all_filters( 'wpcom_gutenberg_rtc_providers' );
		parent::tear_down();
	}

projects/packages/jetpack-mu-wpcom/src/features/gutenberg-rtc/gutenberg-rtc.php:65

  • wpcom_enqueue_gutenberg_rtc_assets() calls wpcom_get_gutenberg_rtc_providers() twice (once into $providers and again when building the inline data). If provider resolution is filter-driven, calling it twice can be inconsistent and makes debugging harder. Reuse the already-computed $providers when building the JSON data.
	$providers = wpcom_get_gutenberg_rtc_providers();

	// If HTTP polling (Gutenberg’s built-in default provider when this script isn’t enqueued)
	// is the only provider being used, then we don’t need to inject any assets since that’s
	// already the default behavior.
	if ( count( $providers ) === 1 && in_array( 'http-polling', $providers, true ) ) {
		return;
	}

	$handle = jetpack_mu_wpcom_enqueue_assets( 'gutenberg-rtc', array( 'js' ) );

	$data = wp_json_encode(
		array(
			'providers' => wpcom_get_gutenberg_rtc_providers(),
		),
		JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +30 to 44
$allowed_providers = array( 'http-polling', 'pinghub' );
$providers = apply_filters( 'wpcom_gutenberg_rtc_providers', array( 'pinghub' ) );
if ( ! is_array( $providers ) ) {
return array();
}

return array_values(
array_filter(
$providers,
function ( $provider ) use ( $allowed_providers ) {
return in_array( $provider, $allowed_providers, true );
}
)
);
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions "limit 2 collaborators", but this change set only adds an allowlist + enqueue behavior for the http-polling provider and doesn’t appear to implement any collaborator limit. If the limit is handled elsewhere, consider linking to it in the PR description; otherwise, either implement the limit here or adjust the description to match what this PR actually changes.

Copilot uses AI. Check for mistakes.
@arthur791004 arthur791004 added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. labels Mar 9, 2026
@arthur791004 arthur791004 merged commit 76970a6 into trunk Mar 9, 2026
76 checks passed
@arthur791004 arthur791004 deleted the feat/gb-rtc-default-provider branch March 9, 2026 06:09
@github-actions github-actions bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [mu wpcom Feature] Gutenberg Rtc [Package] Jetpack mu wpcom WordPress.com Features [Plugin] mu wpcom jetpack-mu-wpcom plugin [Plugin] Wpcomsh [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants