Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed block unique ID generation
  • Loading branch information
nk-o committed Aug 23, 2019
1 parent 54ea4ad commit f0a7ea8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/gutenberg/extend/styles/index.jsx
Expand Up @@ -401,20 +401,23 @@ const withNewAttrs = createHigherOrderComponent( ( BlockEdit ) => {
ghostkitClassname,
} = attributes;

// prevent unique ID duplication after block duplicated.
if ( checkDuplicates ) {
const allBlocks = this.getAllBlocks();
// create block ID.
if ( ! ghostkitId || checkDuplicates ) {
const usedIds = {};

allBlocks.forEach( ( data ) => {
if ( data.clientId && data.attributes && data.attributes.ghostkitId ) {
usedIds[ data.attributes.ghostkitId ] = data.clientId;
// prevent unique ID duplication after block duplicated.
if ( checkDuplicates ) {
const allBlocks = this.getAllBlocks();
allBlocks.forEach( ( data ) => {
if ( data.clientId && data.attributes && data.attributes.ghostkitId ) {
usedIds[ data.attributes.ghostkitId ] = data.clientId;

if ( data.clientId !== clientId && data.attributes.ghostkitId === ghostkitId ) {
ghostkitId = '';
if ( data.clientId !== clientId && data.attributes.ghostkitId === ghostkitId ) {
ghostkitId = '';
}
}
}
} );
} );
}

// prepare new block id.
if ( clientId && ! ghostkitId && typeof ghostkitId !== 'undefined' ) {
Expand Down

0 comments on commit f0a7ea8

Please sign in to comment.