themeum / qubely

Qubely Blocks – Full-fledged Gutenberg Toolkit
GNU General Public License v3.0
84 stars 36 forks source link

Incomplete 'isQubelyBlock' causes CSS to not be saved #35

Closed ahegyes closed 4 years ago

ahegyes commented 4 years ago

Hello!

Inside the file 'assets/reactjs/src/helpers/ParseCss.js' there is a function called 'isQubelyBlock' which checks if the current blocks inside the Gutenberg DOM are from Qubely or not.

The function checks the up to 3 levels of nesting, but that is not necessarily "complete" always. For example, I have a few pages where the Qubely blocks are down at the 4th level of nesting and thus this function always returns that there are no Qubely blocks.

A better way of checking would be recursively since that would ensure that all the levels are checked.

Something like this (not tested yet):

function isQubelyBlock(blocks) {
    let isQubely = false;

    blocks.forEach(block => {
      if (block.name.indexOf('qubely/') != -1) {
            isQubely = true;
        }

        if ( !isQubely && block.innerBlocks && (block.innerBlocks).length > 0) {
            isQubely = isQubelyBlock(block.innerBlocks);
        }
    });

    return isQubely;
}
fai-sal commented 4 years ago

Dear @ahegyes,
Thank you for pointing out the issue and also for the probable solution. I have checked the issue and will update Qubely solving this issue. Thank you once again & have a nice day.

ahegyes commented 4 years ago

Hi @fai-sal,

Thanks a lot for looking into this and fixing the issue! I saw the fix applied already on the dev branch which makes me excited about the next release :)

However, today I noticed a similar issue in the same file, but this time in the function recursive_block_map. At line 172 there is an if check for a Qubely block type. BUT, if the qubely block is nested somewhere inside the current block, it will never be found.

There should be an 'else' case which calls the 'recursive_block_map' function on the innerBlocks of the element in this case.