Skip to content

Commit

Permalink
Wait until rendering has finished in BlocksForm before trying to upda…
Browse files Browse the repository at this point in the history
…te block state
  • Loading branch information
JeffersonBledsoe committed Feb 13, 2025
1 parent eba61ab commit 4ad982a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/volto/src/components/manage/Blocks/Block/BlocksForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ const BlocksForm = (props) => {

const blockList = getBlocks(properties);

useEffect(() => {
for (const [n, v] of blockList) {
if (!v) {
const newFormData = deleteBlock(properties, n, intl);
onChangeFormData(newFormData);
}
}
}, [blockList]);

Check warning on line 81 in packages/volto/src/components/manage/Blocks/Block/BlocksForm.jsx

View workflow job for this annotation

GitHub Actions / ESlint

React Hook useEffect has missing dependencies: 'intl', 'onChangeFormData', and 'properties'. Either include them or remove the dependency array

const blocksWithData = blockList.filter((block) => !!block[1]);

const dispatch = useDispatch();
const intl = useIntl();

Expand Down Expand Up @@ -260,13 +271,6 @@ const BlocksForm = (props) => {
// to be removed when the user saves the page next. Otherwise the invalid
// blocks would linger for ever.

for (const [n, v] of blockList) {
if (!v) {
const newFormData = deleteBlock(properties, n, intl);
onChangeFormData(newFormData);
}
}

useEvent('voltoClickBelowContent', () => {
if (!config.experimental.addBlockButton.enabled || !isMainForm) return;
onSelectBlock(
Expand Down Expand Up @@ -303,7 +307,7 @@ const BlocksForm = (props) => {
>
<fieldset className="invisible" disabled={!editable}>
<DragDropList
childList={blockList}
childList={blocksWithData}
onMoveItem={(result) => {
const { source, destination } = result;
if (!destination) {
Expand Down

0 comments on commit 4ad982a

Please sign in to comment.