Skip to content

Commit

Permalink
fix: Use clone to avoid pass by reference (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
sneridagh authored Mar 12, 2024
1 parent 927ccd3 commit b4fc613
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { cloneDeep } from 'lodash';
import codeSVG from '@plone/volto/icons/code.svg';
import showcaseSVG from '@plone/volto/icons/showcase.svg';

Expand Down Expand Up @@ -96,16 +97,15 @@ const applyConfig = (config) => {
};

// Add Blocks to gridBlock and accordionBlock
// It's important to maintain the chain, and do not introduce pass by reference in
// the internal `blocksConfig` object, so we clone the object to avoid this.
['gridBlock', 'accordion'].forEach((blockId) => {
const block = config.blocks.blocksConfig[blockId];
if (block !== undefined) {
config.blocks.blocksConfig.gridBlock = {
...config.blocks.blocksConfig.gridBlock,
blocksConfig: {
...config.blocks.blocksConfig,
},
allowedBlocks: [...config.blocks.blocksConfig.gridBlock.allowedBlocks, 'codeBlock', 'mermaidBlock', 'gistBlock'],
};
block.allowedBlocks = [...block.allowedBlocks, 'codeBlock', 'mermaidBlock', 'gistBlock'];
block.blocksConfig.codeBlock = cloneDeep(config.blocks.blocksConfig.codeBlock);
block.blocksConfig.mermaidBlock = cloneDeep(config.blocks.blocksConfig.mermaidBlock);
block.blocksConfig.gistBlock = cloneDeep(config.blocks.blocksConfig.gistBlock);
}
});

Expand Down

0 comments on commit b4fc613

Please sign in to comment.