Redactor crashes NodeBB

Technical Support
  • Hi Devs,
    It seems that Redactor may have an issue with the latest master.

    When opened, it crashes nodebb with the below. The issue can be reproduced, again and again.
    I also got this during build - perhaps that's related:

    Browserslist: caniuse-lite is outdated. Please run next command `yarn upgrade caniuse-lite browserslist`
    

    Crash log:

    2018-12-24 - error: uncaughtException: Cannot read property 'children' of undefined
    TypeError: Cannot read property 'children' of undefined
        at nodebb/node_modules/nodebb-plugin-composer-default/websockets.js:128:73
        at Array.filter (<anonymous>)
        at nodebb/node_modules/nodebb-plugin-composer-default/websockets.js:119:44
        at nextTask (nodebb/node_modules/async/dist/async.js:5324:14)
        at next (nodebb/node_modules/async/dist/async.js:5331:9)
        at nodebb/node_modules/async/dist/async.js:969:16
        at nodebb/node_modules/async/dist/async.js:3888:9
        at nodebb/node_modules/async/dist/async.js:473:16
        at iterateeCallback (nodebb/node_modules/async/dist/async.js:992:24)
        at nodebb/node_modules/async/dist/async.js:969:16
        at nodebb/node_modules/async/dist/async.js:3885:13
        at nodebb/src/privileges/categories.js:98:5
        at nodebb/node_modules/async/dist/async.js:473:16
        at next (nodebb/node_modules/async/dist/async.js:5329:29)
        at nodebb/node_modules/async/dist/async.js:969:16
        at nodebb/src/privileges/helpers.js:81:4 {"error":{},"stack":"Type
    
  • This issue may be related to permission.
    Normal user with permission crashes nodebb upon redactor opening, while Admin does not.

  • Hi @baris ,

    The category is defined. The problem is the access to the array cidToCategory.
    I reviewed its content with the debugger, and the c.parent.cid cannot be used to access it:
    cidToCategory does not have linear index that matches the internal cid:

    Index: Data:
    1: {cid: 1, icon: "hidden", link: "", …}
    2: {cid: 31, icon: "hidden", link:…}
    3: {cid: 9, icon: …}
    4: {cid: 37, icon: "hidden", link: …}
    

    Furthermore, Some parts of the array is undefined.

    This is the definition of cidToCategory :

    var cidToCategory = _.zipObject(cids, results.categories);
    

    The bad access occures in line 128, where the cid is used:

    cidToCategory[c.parent.cid].children = cidToCategory[c.parent.cid].children.filter(child => {
    						return child.cid !== c.cid;
    
  • @JJSagan Hmm that's definitely weird cidToCategory should be an object with the keys being category ids.

    On my environment I get this.

    { '1':
       { bgColor: '#fda34b',
         cid: 1,
         class: 'col-md-3 col-xs-6',
         color: '#fff',
         description: 'Announcements regarding our community',
         descriptionParsed: '<p>Announcements regarding our community</p>\n',
         disabled: 0,
         icon: 'fa-bullhorn',
         imageClass: 'cover',
         isSection: 0,
         link: '',
         name: 'Announcements',
         numRecentReplies: 1,
         order: 1,
         parentCid: 0,
         post_count: 33,
         slug: '1/announcements',
         topic_count: 5,
         totalPostCount: 33,
         totalTopicCount: 5,
         children: [],
         parent: undefined },
      '2':
       { bgColor: '#59b3d0',
         cid: 2,
         class: 'col-md-3 col-xs-6',
         color: '#fff',
         description: 'A place to talk about whatever you want',
         descriptionParsed: '<p>A place to talk about whatever you want</p>\n',
         disabled: 0,
         icon: 'fa-comments-o',
         imageClass: 'cover',
         isSection: 0,
         link: '',
         name: 'General Discussion',
         numRecentReplies: 1,
         order: 2,
         parentCid: 0,
         post_count: 20,
         slug: '2/general-discussion',
         topic_count: 7,
         totalPostCount: 20,
         totalTopicCount: 7,
         children: [ [Object] ],
         parent: undefined },
      '3':
       { bgColor: '#86ba4b',
         cid: 3,
         class: 'col-md-3 col-xs-6',
         color: '#fff',
         description: 'Blog posts from individual members',
         descriptionParsed: '<p>Blog posts from individual members</p>\n',
         disabled: 0,
         icon: 'fa-newspaper-o',
         imageClass: 'cover',
         isSection: 0,
         link: '',
         name: 'Blogs',
    ...
    
  • Hi @baris ,

    From what I see, the categories on my setup are well defined and working. I also made a quick check with group privileges - to make sure access is granted to the target category, and it looks like we are ok.

    I may have, over time, obsoleted several categories, and maybe later returned some or all to active duty. Thus, the cid array may not be perfectly "linear".

    Another direction: I am using postgress, so maybe the array that is fetched from the DB is not sorted. I hope @Ben-Lubar might be able to shed some light here.

    Thanks again for looking into this! highly appreciated.

  • Can you put a console.log(cids, cidToCategory); right after the _.zipObject call and let me know the output? It shouldn't matter if the cids array is linear, as long as all the items in it are valid category ids.

  • @baris said in Redactor crashes NodeBB:

    console.log(cids, cidToCategory);

    It looks good. As far as I can tell, all items are valid. The issue is that the array index (below, for example first line: 37), does not matches internal cid (below, 2nd line: 10). Thus, the array may not be accessed with the c.parent.cid.

    Perhaps we need to sort the array first, or use filter?

    Console.log output:

    '37':
     { cid: 10,
       icon: 'hidden',
       link: '',
    ...
    } },
    '38':
     { cid: 34,
       icon: 'hidden',
       link: '',
    ...
    } },
    '39':
     { cid: 40,
       icon: 'hidden',
       link: '',
    
  • Yep, that's the issue, I am working on a fix.

  • Should be fixed on latest master, let me know the new output and if all cids match the internal cid.

  • Hi @baris
    Your latest code fixes the issue at hand.
    Thank you so much!
    JJ.


Suggested Topics