Skip to content

Commit

Permalink
Remove synced blocks from lastBlockInserted (#52558)
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Jul 13, 2023
1 parent b690db2 commit 306c6e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion packages/block-editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,6 @@ export function lastBlockInserted( state = {}, action ) {
switch ( action.type ) {
case 'INSERT_BLOCKS':
case 'REPLACE_BLOCKS':
case 'REPLACE_INNER_BLOCKS':
if ( ! action.blocks.length ) {
return state;
}
Expand Down
21 changes: 14 additions & 7 deletions packages/block-editor/src/store/test/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3328,25 +3328,32 @@ describe( 'state', () => {
expect( state.clientIds ).toEqual( [ clientIdOne, clientIdTwo ] );
} );

it( 'should return client ids of all blocks when inner blocks are replaced with REPLACE_INNER_BLOCKS', () => {
const clientIdOne = '62bfef6e-d5e9-43ba-b7f9-c77cf354141f';
const clientIdTwo = '9db792c6-a25a-495d-adbd-97d56a4c4189';
it( 'should return client ids of the original blocks when inner blocks are replaced with REPLACE_INNER_BLOCKS', () => {
const initialBlocks = deepFreeze( [
'62bfef6e-d5e9-43ba-b7f9-c77cf354141f',
'9db792c6-a25a-495d-adbd-97d56a4c4189',
] );

const action = {
blocks: [
{
clientId: clientIdOne,
clientId: 'afd1cb17-2c08-4e7a-91be-007ba7ddc3a1',
},
{
clientId: clientIdTwo,
clientId: '14501cc2-90a6-4f52-aa36-ab6e896135d1',
},
],
type: 'REPLACE_INNER_BLOCKS',
};

const state = lastBlockInserted( {}, action );
const state = lastBlockInserted(
{
clientIds: initialBlocks,
},
action
);

expect( state.clientIds ).toEqual( [ clientIdOne, clientIdTwo ] );
expect( state.clientIds ).toEqual( initialBlocks );
} );

it( 'should return empty state if last block inserted is called with action RESET_BLOCKS', () => {
Expand Down

1 comment on commit 306c6e3

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 306c6e3.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5547072563
📝 Reported issues:

Please sign in to comment.