Skip to content

Commit

Permalink
Merge pull request #292 from 10up/fix/291
Browse files Browse the repository at this point in the history
fix/291: Add check for empty default attribute in `Repeater` component
  • Loading branch information
fabiankaegy authored Jan 31, 2024
2 parents 8be1c91 + efcf67b commit f1c6e4e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/repeater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export const AttributeRepeater = ({ children, attribute, addButton, allowReorder
};
});

defaultRepeaterData[0].id = uuid();
if ( defaultRepeaterData.length ) {
defaultRepeaterData[0].id = uuid();
}

const handleOnChange = (value) => {
updateBlockAttributes(clientId, { [attribute]: value });
Expand Down Expand Up @@ -114,7 +116,7 @@ export const AbstractRepeater = ({
const defaultValueCopy = JSON.parse(JSON.stringify(defaultValue));

if (!defaultValue.length) {
defaultValueCopy.push([]);
defaultValueCopy.push({});
}

defaultValueCopy[0].id = uuid();
Expand Down

0 comments on commit f1c6e4e

Please sign in to comment.