-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Collaboration: only report changed properties from the default sync config #79908
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
Merged
+196
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
test/e2e/specs/editor/collaboration/http-only/collaboration-taxonomy-record-dirty.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import type { Page } from '@playwright/test'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { test, expect } from '../fixtures'; | ||
|
|
||
| /** | ||
| * Regression test for https://github.com/WordPress/gutenberg/issues/79907. | ||
| * | ||
| * Opening the pre-publish panel resolves the default category record, which | ||
| * loads the term document into the sync manager. When another peer has the | ||
| * same term document loaded, its updates are relayed to this client. The | ||
| * default sync config must not report the unchanged record as edits when | ||
| * those updates arrive. If it does, the term becomes dirty, | ||
| * `hasNonPostEntityChanges()` returns true, and the Publish button silently | ||
| * turns into "Save". | ||
| */ | ||
| test.describe( 'Collaboration - synced taxonomy records', () => { | ||
| test( 'pre-publish panel does not dirty the default category record', async ( { | ||
| collaborationUtils, | ||
| requestUtils, | ||
| page, | ||
| } ) => { | ||
| const post = await requestUtils.createPost( { | ||
| title: 'Taxonomy record dirty regression', | ||
| content: | ||
| '<!-- wp:paragraph --><p>Hello world</p><!-- /wp:paragraph -->', | ||
| status: 'draft', | ||
| date_gmt: new Date().toISOString(), | ||
| } ); | ||
|
|
||
| const publishPanelFor = ( target: Page ) => | ||
| target.locator( '.editor-post-publish-panel' ); | ||
|
|
||
| /* | ||
| * The toggle is aria-disabled while the editor initializes, which | ||
| * Playwright's actionability checks don't wait for, so retry the | ||
| * click until the panel opens. | ||
| */ | ||
| const openPrePublishPanel = async ( target: Page ) => { | ||
| const toggle = target | ||
| .getByRole( 'region', { name: 'Editor top bar' } ) | ||
| .getByRole( 'button', { name: 'Publish', exact: true } ); | ||
| const panel = publishPanelFor( target ); | ||
| await expect( async () => { | ||
| if ( ! ( await panel.isVisible() ) ) { | ||
| await toggle.click(); | ||
| } | ||
| await expect( panel ).toBeVisible( { timeout: 2000 } ); | ||
| } ).toPass( { timeout: 20000 } ); | ||
| }; | ||
|
|
||
| // Session 1: open the post and the pre-publish panel. This resolves | ||
| // the default category record and loads the term document into the | ||
| // sync manager, which starts exchanging it with the server. | ||
| await collaborationUtils.openPost( post.id ); | ||
| await openPrePublishPanel( page ); | ||
|
|
||
| // Session 2: a second tab for the same user opens the same post and | ||
| // panel. Each tab is a distinct sync client, so the term document | ||
| // updates of one tab are relayed to the other. | ||
| const page2 = await page.context().newPage(); | ||
| await page2.goto( `/wp-admin/post.php?post=${ post.id }&action=edit` ); | ||
| await collaborationUtils.waitForCollaborationReady( page2 ); | ||
| await openPrePublishPanel( page2 ); | ||
|
|
||
| // Wait until both tabs have exchanged sync messages that include the | ||
| // default category room. | ||
| const waitForCategorySyncExchange = ( target: Page ) => | ||
| target.waitForResponse( | ||
| ( response ) => | ||
| response.url().includes( 'wp-sync' ) && | ||
| response.status() === 200 && | ||
| ( response.request().postData() ?? '' ).includes( | ||
| 'taxonomy/category' | ||
| ), | ||
| { timeout: 20000 } | ||
| ); | ||
| await Promise.all( [ | ||
| waitForCategorySyncExchange( page ), | ||
| waitForCategorySyncExchange( page2 ), | ||
| ] ); | ||
|
|
||
| // The relayed updates carry no actual changes, so the term record | ||
| // must not accumulate edits in either tab. Poll across several sync | ||
| // cycles; on regression the record turns dirty within one cycle. | ||
| const watchForDirtyCategory = ( target: Page ) => | ||
| target.evaluate( | ||
| () => | ||
| new Promise( ( resolve ) => { | ||
| const started = Date.now(); | ||
| const interval = setInterval( () => { | ||
| const hasEdits = window.wp.data | ||
| .select( 'core' ) | ||
| .hasEditsForEntityRecord( | ||
| 'taxonomy', | ||
| 'category', | ||
| 1 | ||
| ); | ||
| if ( hasEdits ) { | ||
| clearInterval( interval ); | ||
| resolve( true ); | ||
| } else if ( Date.now() - started > 10000 ) { | ||
| clearInterval( interval ); | ||
| resolve( false ); | ||
| } | ||
| }, 200 ); | ||
| } ) | ||
| ); | ||
| const [ becameDirty, becameDirty2 ] = await Promise.all( [ | ||
| watchForDirtyCategory( page ), | ||
| watchForDirtyCategory( page2 ), | ||
| ] ); | ||
| expect( becameDirty ).toBe( false ); | ||
| expect( becameDirty2 ).toBe( false ); | ||
|
|
||
| // The user-visible symptom: the panel button must still read | ||
| // "Publish", not "Save". | ||
| await expect( | ||
| publishPanelFor( page ).locator( | ||
| '.editor-post-publish-button__button' | ||
| ) | ||
| ).toHaveText( 'Publish' ); | ||
|
|
||
| await page2.close(); | ||
| } ); | ||
| } ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
It's unsettling this didn't come up in the original code review. The function name says "get changes", but the function body doesn't compute any changes. The caller passes two arguments, one being the edited record, but this function only accepts one argument. Also, are we missing any TypeScript checks? Calling a function of one argument with two arguments should have come up in CI checks 🤔
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.
gutenberg/packages/sync/src/manager.ts
Lines 701 to 706 in 37cbe35
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.
It is assigned to a
SyncConfigobject incrdt.tswhich is valid.The following does not cause any TypeScript warnings.
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.
Good question! It looks like we added the
editedRecordparameter way back in #72262, but didn't add it todefaultGetChangesFromCRDTDoc(), only the post version.As to why we can call this function without all parameters, TypeScript docs have an explanation here. JS uses optional parameters often like
foreachwhich provideselement,index, andarrayparameters, but most people just want theelementand to ignore the rest without an error.Uh oh!
There was an error while loading. Please reload this page.
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 @maxschmeling, TIL! The example is indeed intact in the TypeScript Playground:
TypeScript FAQ explains why they made that choice:
Too bad, it would have been useful to have that as an option.