Skip to content

Commit

Permalink
Fix further internal blocksConfig pass by reference present in core…
Browse files Browse the repository at this point in the history
… (related to #5850) (#5859)
  • Loading branch information
sneridagh authored Mar 7, 2024
1 parent 7bc30cb commit a496558
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/volto-slate/news/5859.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix other occurrences of mutable (referenced) objects when assigning the default inner `blocksConfig` object for the `grid` block, pass by value instead. sneridagh
5 changes: 4 additions & 1 deletion packages/volto-slate/src/blocks/Text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import TextBlockView from './TextBlockView';
import TextBlockEdit from './TextBlockEdit';
import TextBlockSchema from './TextBlockSchema';
import { cloneDeep } from 'lodash';

import {
goDown,
Expand Down Expand Up @@ -145,7 +146,9 @@ export default function applyConfig(config) {
// This is required in order to initialize the inner blocksConfig
// for the grid block, since the slate block lives in an add-on
// it should be responsible to fill itself into the grid configuration
config.blocks.blocksConfig.gridBlock.blocksConfig.slate = slateBlockConfig;
// The cloneDeep is mandatory in order to not mess with pass by reference problems
config.blocks.blocksConfig.gridBlock.blocksConfig.slate =
cloneDeep(slateBlockConfig);
}

return config;
Expand Down
1 change: 1 addition & 0 deletions packages/volto/news/5859.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix other occurrences of mutable (referenced) objects when assigning the default inner `blocksConfig` object for the `grid` block, pass by value instead. sneridagh
12 changes: 4 additions & 8 deletions packages/volto/src/config/Blocks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -520,14 +520,10 @@ const blocksConfig = {
// block behave in it (= no schemaEnhancer fields for teasers inside a grid)
// Afterwards, it can be further customized in add-ons using the same technique.
blocksConfig.gridBlock.blocksConfig = cloneDeep(blocksConfig);
blocksConfig.gridBlock.blocksConfig.teaser = {
...blocksConfig.teaser,
schemaEnhancer: gridTeaserDisableStylingSchema,
};
blocksConfig.gridBlock.blocksConfig.image = {
...blocksConfig.image,
schemaEnhancer: gridImageDisableSizeAndPositionHandlersSchema,
};
blocksConfig.gridBlock.blocksConfig.teaser.schemaEnhancer =
gridTeaserDisableStylingSchema;
blocksConfig.gridBlock.blocksConfig.image.schemaEnhancer =
gridImageDisableSizeAndPositionHandlersSchema;

const requiredBlocks = ['title'];

Expand Down

0 comments on commit a496558

Please sign in to comment.