"TypeError: fontsize.attr(...).appendTo(...)[0] is undefined" Issue With NavBar

Created on 30 November 2013, over 11 years ago
Updated 24 April 2025, 12 days ago

Greetings to all.

In a simple, non-nested superfish menu that is configured with the "NavBar" menu type (as opposed to the default "Horizontal", which appears to introduce an accordion-styled menu when the screen width becomes too small [i.e., mobile]), the following error might be observed when refreshing any of the site pages:

TypeError: fontsize.attr(...).appendTo(...)[0] is undefined

at line 39 of sites/all/libraries/superfish/supersubs.js, which is the following line:

.appendTo($$)[0].clientWidth; //clientWidth is faster than width()

It appears, in this case, that the $$ result set does not contain at least one item, is consequently not an array, and the appendTo method is unable to append anything to it (the target). Consequently, the subsequent [0] reference against it results in undefined. This raises an exception when the clientWidth property is invoked on undefined.

I observed that following snippet of code just a few lines prior to this issue:

      // Jump on level if it's a "NavBar"
      if ($$.hasClass('sf-navbar')) {
        $$ = $$.children('li').children('ul');
      }

(I think 'on' in the comment was supposed to read 'one', but that doesn't matter.) Changing it to the following seemed to resolve the issue, but I'm not sure how safe this change is:

      // Jump on level if it's a "NavBar"
//      if ($$.hasClass('sf-navbar')) {
//        $$ = $$.children('li').children('ul');
//      }

      if ($$.hasClass('sf-navbar') && $$.children('li').children('ul')[0]) {
        $$ = $$.children('li').children('ul');
      }

I decided to make this change in my local code base because it's obvious $$ needs to contain a query set of at least one element. But please point out any errors in my assumptions, if you'd be so kind.

Many thanks,
Nick

πŸ› Bug report
Status

Closed: outdated

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States nkat2112

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024