[wp-trac] [WordPress Trac] #46948: Twenty Nineteen - JS error on mobile menu when no visible items

WordPress Trac noreply at wordpress.org
Tue Apr 16 15:00:46 UTC 2019


#46948: Twenty Nineteen - JS error on mobile menu when no visible items
---------------------------+-----------------------------
 Reporter:  anevins        |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Bundled Theme  |    Version:
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 Looks like there's an issue with the JS that populates the 'more' (...)
 menu on mobile. If there are no visible menu links inside the main menu on
 mobile and all of them are inside the 'more' menu, then the JS will break.
 I do not think this is an issue on a Child Theme.

 Line 128 priority-menu.js:

 {{{
 prependElement( hiddenList, ! visibleList.lastChild || null ===
 visibleList.lastChild ? visibleList.previousElementSibling :
 visibleList.lastChild );

 }}}

 Regarding `.lastChild`.

 The `visibleList` element:

 {{{
 // Adds the necessary UI to operate the menu.
 var visibleList  = container.parentNode.querySelector('.main-menu[id]');

 }}}

 If no items are inside the visible list (and all items are inside the more
 menu) then `visibleList` will indeed return as a Node, however `lastChild`
 will return null.

 This means the value will not be catched properly by this inline
 condition:
 {{{
 visibleList.previousElementSibling : visibleList.lastChild
 }}}

 And `null` will be passed to the second argument of the `prependElement`
 function when it is not a node - and cause a JS error.



 _https://wordpress.org/support/topic/javascript-error-on-child-theme
 /#post-11433882_

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/46948>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list