Skip to content

Commit 81ec94f

Browse files
committed
fix: add checks before migrating
1 parent ba514ab commit 81ec94f

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

src/block-components/alignment/deprecated/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ export const deprecateInnerBlockRowGapAndContainerHeight = {
2929
const getAttrName = getAttrNameFunction( attrNameTemplate )
3030
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
3131

32+
const newAttributes = {
33+
...attributes,
34+
}
35+
3236
const containerHeight = getAttribute( 'containerHeight' )
3337
const innerBlockRowGap = getAttribute( 'innerBlockRowGap' )
3438

35-
const newAttributes = {
36-
...attributes,
37-
[ getAttrName( 'containerHeight' ) ]: String( containerHeight ),
38-
[ getAttrName( 'innerBlockRowGap' ) ]: String( innerBlockRowGap ),
39+
if ( typeof containerHeight === 'number' ) {
40+
newAttributes[ getAttrName( 'containerHeight' ) ] = String( containerHeight )
41+
}
42+
43+
if ( typeof innerBlockRowGap === 'number' ) {
44+
newAttributes[ getAttrName( 'innerBlockRowGap' ) ] = String( innerBlockRowGap )
3945
}
4046

4147
return newAttributes

src/block-components/columns/deprecated/index.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,24 @@ export const deprecateColumnAndRowGap = {
4141
const getAttrName = getAttrNameFunction( attrNameTemplate )
4242
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
4343

44+
const newAttributes = {
45+
...attributes,
46+
}
47+
4448
const columnSpacing = getAttribute( 'columnSpacing' )
4549
const columnGap = getAttribute( 'columnGap' )
4650
const rowGap = getAttribute( 'rowGap' )
4751

48-
const newAttributes = {
49-
...attributes,
50-
[ getAttrName( 'columnSpacing' ) ]: String( columnSpacing ),
51-
[ getAttrName( 'columnGap' ) ]: String( columnGap ),
52-
[ getAttrName( 'rowGap' ) ]: String( rowGap ),
52+
if ( typeof columnSpacing === 'number' ) {
53+
newAttributes[ getAttrName( 'columnSpacing' ) ] = String( columnSpacing )
54+
}
55+
56+
if ( typeof columnGap === 'number' ) {
57+
newAttributes[ getAttrName( 'columnGap' ) ] = String( columnGap )
58+
}
59+
60+
if ( typeof rowGap === 'number' ) {
61+
newAttributes[ getAttrName( 'rowGap' ) ] = String( rowGap )
5362
}
5463

5564
return newAttributes

src/block-components/helpers/size/deprecated.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ export const deprecateSizeControlHeight = {
2929
const getAttrName = getAttrNameFunction( attrNameTemplate )
3030
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
3131

32-
const height = getAttribute( 'height' )
33-
3432
const newAttributes = {
3533
...attributes,
36-
[ getAttrName( 'height' ) ]: String( height ),
34+
}
35+
36+
const height = getAttribute( 'height' )
37+
38+
if ( typeof height === 'number' ) {
39+
newAttributes[ getAttrName( 'height' ) ] = String( height )
3740
}
3841

3942
return newAttributes

src/block-components/typography/deprecated.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ export const deprecateTypographyFontSize = {
130130
const getAttrName = getAttrNameFunction( attrNameTemplate )
131131
const getAttribute = _attrName => attributes[ getAttrName( _attrName ) ]
132132

133-
const fontSize = getAttribute( 'fontSize' )
134-
135133
const newAttributes = {
136134
...attributes,
137-
[ getAttrName( 'fontSize' ) ]: String( fontSize ),
135+
}
136+
137+
const fontSize = getAttribute( 'fontSize' )
138+
139+
if ( typeof fontSize === 'number' ) {
140+
newAttributes[ getAttrName( 'fontSize' ) ] = String( fontSize )
138141
}
139142

140143
return newAttributes

0 commit comments

Comments
 (0)