Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.0/11161.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/11161

* https://github.com/WordPress/gutenberg/pull/75739
25 changes: 13 additions & 12 deletions lib/compat/wordpress-7.0/collaboration.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,19 @@ function () use ( $option_name ) {
);
}
add_action( 'admin_init', 'gutenberg_register_real_time_collaboration_setting' );
}

/**
* Injects the real-time collaboration setting into a global variable.
*/
function gutenberg_inject_real_time_collaboration_setting() {
if ( get_option( 'wp_enable_real_time_collaboration', '0' ) ) {
wp_add_inline_script(
'wp-core-data',
'window._wpCollaborationEnabled = true;',
'after'
);
}
/**
* Injects the real-time collaboration setting into a global variable.
*/
function gutenberg_inject_real_time_collaboration_setting() {
if ( get_option( 'wp_enable_real_time_collaboration' ) ) {
wp_add_inline_script(
'wp-core-data',
'window._wpCollaborationEnabled = true;',
'after'
);
}
add_action( 'admin_init', 'gutenberg_inject_real_time_collaboration_setting' );
}
add_action( 'admin_init', 'gutenberg_inject_real_time_collaboration_setting' );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did this all move outside of the condition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because otherwise, with E2E tests running against WP trunk, RTC would be disabled by default until the backport PR is merged.

add_filter( 'default_option_wp_enable_real_time_collaboration', '__return_true' );
20 changes: 0 additions & 20 deletions lib/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,3 @@ function _gutenberg_migrate_remove_fse_drafts() {
delete_option( 'gutenberg_last_synchronize_theme_template_checks' );
delete_option( 'gutenberg_last_synchronize_theme_template-part_checks' );
}

/**
* Replace unprefixed option enable_real_time_collaboration with prefixed version.
*
* Adds a `wp_` prefix to the option name to follow the convention for adding new
* options to WordPress since WP 5.8.0.
*
* @since 22.6.0
*/
function _gutenberg_migrate_enable_real_time_collaboration() {
$current_value = get_option( 'enable_real_time_collaboration', '0' );

update_option( 'wp_enable_real_time_collaboration', $current_value );
delete_option( 'enable_real_time_collaboration' );
}

// Deletion of the `_wp_file_based` term (in _gutenberg_migrate_remove_fse_drafts) must happen
// after its taxonomy (`wp_theme`) is registered. This happens in `gutenberg_register_wp_theme_taxonomy`,
// which is hooked into `init` (default priority, i.e. 10).
add_action( 'init', '_gutenberg_migrate_database', 20 );
7 changes: 2 additions & 5 deletions packages/core-data/src/utils/crdt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,8 @@ export function getPostChangesFromCRDTDoc(
// Do not overwrite a "floating" date. Borrowing logic from the
// isEditedPostDateFloating selector.
const currentDateIsFloating =
[ 'draft', 'auto-draft', 'pending' ].includes(
ymap.get( 'status' ) as string
) &&
( null === currentValue ||
editedRecord.modified === currentValue );
null === currentValue ||
editedRecord.modified === currentValue;

if ( currentDateIsFloating ) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ test.describe( 'Collaboration with meta boxes', () => {
editor,
page,
} ) => {
// Ensure collaboration is enabled (the fixture enables it, but
// be explicit to match the pattern of other collaboration tests).
await collaborationUtils.setCollaboration( true );

// Create a draft post.
const post = await requestUtils.createPost( {
title: 'Meta Box Lock Test',
Expand All @@ -43,6 +39,9 @@ test.describe( 'Collaboration with meta boxes', () => {
fullscreenMode: false,
} );

// Wait for collaboration runtime and entity record to be ready.
await collaborationUtils.waitForEntityReady( page );

// Wait for meta boxes to initialize and disable collaboration.
// collaborationSupported starts as true, then the meta box hook
// sets it to false once meta boxes are detected.
Expand Down
87 changes: 41 additions & 46 deletions test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,51 +50,6 @@ export default class CollaborationUtils {
this.primaryPage = page;
}

/**
* Set the real-time collaboration WordPress setting.
*
* Uses the form-based approach (similar to setGutenbergExperiments)
* because this setting is registered on admin_init in the "writing"
* group and is not exposed via /wp/v2/settings.
*
* @param enabled Whether to enable or disable collaboration.
*/
async setCollaboration( enabled: boolean ) {
const response = await this.requestUtils.request.get(
'/wp-admin/options-writing.php'
);
const html = await response.text();
const nonce = html.match( /name="_wpnonce" value="([^"]+)"/ )![ 1 ];

// WordPress core (7.0+) uses 'enable_real_time_collaboration',
// while the Gutenberg plugin uses 'wp_enable_real_time_collaboration'.
// Detect which field name is present on the page.
const optionName = html.includes(
'name="enable_real_time_collaboration"'
)
? 'enable_real_time_collaboration'
: 'wp_enable_real_time_collaboration';

const formData: Record< string, string | number > = {
option_page: 'writing',
action: 'update',
_wpnonce: nonce,
_wp_http_referer: '/wp-admin/options-writing.php',
submit: 'Save Changes',
default_category: 1,
default_post_format: 0,
};

if ( enabled ) {
formData[ optionName ] = 1;
}

await this.requestUtils.request.post( '/wp-admin/options.php', {
form: formData,
failOnStatusCode: true,
} );
}

/**
* Open a collaborative editing session where both the primary user (admin)
* and the second user (collaborator) are editing the same post.
Expand Down Expand Up @@ -355,7 +310,47 @@ export default class CollaborationUtils {
this.secondPage = null;
this.secondEditor = null;
}
await this.setCollaboration( false );
await this.requestUtils.deleteAllUsers();
}
}

/**
* Set the real-time collaboration WordPress setting.
*
* Uses the form-based approach (similar to setGutenbergExperiments)
* because this setting is registered on admin_init in the "writing"
* group and is not exposed via /wp/v2/settings.
*
* @param requestUtils An instance of RequestUtils for making HTTP requests.
* @param enabled Whether to enable or disable collaboration.
*/
export async function setCollaboration(
requestUtils: RequestUtils,
enabled: boolean
): Promise< void > {
const response = await requestUtils.request.get(
'/wp-admin/options-writing.php'
);
const html = await response.text();
const nonce = html.match( /name="_wpnonce" value="([^"]+)"/ )![ 1 ];

const optionName = 'wp_enable_real_time_collaboration';
const optionValue = enabled ? 1 : 0;

const formData: Record< string, string | number > = {
option_page: 'writing',
action: 'update',
_wpnonce: nonce,
_wp_http_referer: '/wp-admin/options-writing.php',
submit: 'Save Changes',
default_category: 1,
default_post_format: 0,
};

formData[ optionName ] = optionValue;

await requestUtils.request.post( '/wp-admin/options.php', {
form: formData,
failOnStatusCode: true,
} );
}
1 change: 0 additions & 1 deletion test/e2e/specs/editor/collaboration/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const test = base.extend< Fixtures >( {
requestUtils,
page,
} );
await utils.setCollaboration( true );
// Clean up any leftover users from previous runs before creating.
await requestUtils.deleteAllUsers();
await requestUtils.createUser( SECOND_USER );
Expand Down
21 changes: 21 additions & 0 deletions test/e2e/specs/editor/plugins/block-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
*/
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );

/**
* Internal dependencies
*/
const {
setCollaboration,
} = require( '../../editor/collaboration/fixtures/collaboration-utils' );

const dummyBlocksContent = `<!-- wp:heading -->
<h2 class="wp-block-heading">This is a dummy heading</h2>
<!-- /wp:heading -->
Expand Down Expand Up @@ -65,6 +72,12 @@ test.describe( 'Block Hooks API', () => {
} else {
containerPost = postObject;
}

/**
* Since the Block Hooks API relies on server-side rendering to insert
* the hooked blocks, there is a fundamental incompatibility with RTC.
*/
await setCollaboration( requestUtils, false );
} );

test.afterAll( async ( { requestUtils } ) => {
Expand All @@ -74,6 +87,7 @@ test.describe( 'Block Hooks API', () => {

await requestUtils.deleteAllPosts();
await requestUtils.deleteAllBlocks();
await setCollaboration( requestUtils, true );
} );

test( `should insert hooked blocks into ${ name } on frontend`, async ( {
Expand Down Expand Up @@ -198,6 +212,12 @@ test.describe( 'Block Hooks API', () => {
} else {
containerPost = postObject;
}

/**
* Since the Block Hooks API relies on server-side rendering to insert
* the hooked blocks, there is a fundamental incompatibility with RTC.
*/
await setCollaboration( requestUtils, false );
} );

test.afterAll( async ( { requestUtils } ) => {
Expand All @@ -207,6 +227,7 @@ test.describe( 'Block Hooks API', () => {

await requestUtils.deleteAllPosts();
await requestUtils.deleteAllBlocks();
await setCollaboration( requestUtils, true );
} );

test( `should insert hooked blocks into ${ name } on frontend`, async ( {
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/specs/editor/various/inner-blocks-templates.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ test.describe( 'Inner blocks templates', () => {
} );

test.beforeEach( async ( { admin } ) => {
await admin.createNewPost();
await admin.createNewPost( {
postType: 'page',
} );
} );

test.afterAll( async ( { requestUtils } ) => {
Expand Down
Loading