Closed (fixed)
Project:
BS Lib
Version:
2.0.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
13 Jul 2026 at 20:54 UTC
Updated:
27 Jul 2026 at 21:00 UTC
Jump to comment: Most recent
bs_lib_page_attachments() attaches drupalSettings.bs_lib.anchor_scroll
only when anchor_scroll.enable is set in bs_lib.settings. However, the
bs_lib/anchor_scroll library can also reach the page as a dependency of other
libraries (for example a theme TOC library that needs BSLib.getFixedElementsOffset()).
In that case js/anchor-scroll.js loads without its settings and throws:
window.BSLib.getFixedElementsOffset() readsdrupalSettings.bs_lib.anchor_scroll unguarded and throws
TypeError: Cannot read
properties of undefined (reading 'anchor_scroll')for every caller.
Drupal.behaviors.BSLibAnchorScroll.attach() readsdrupalSettings.bs_lib.anchor_scroll.exclude_links unguarded and throws on everyanchor_scroll.enable: false in bs_lib.settings.bs_lib/anchor_scroll as a dependency to any custom library and attach it to aDrupal.behaviors.BSLibAnchorScroll throws a TypeErrorBSLib.getFixedElementsOffset() throws as well.Do not rely on the settings being present:
getFixedElementsOffset() returns 0 whendrupalSettings.bs_lib.anchor_scroll is not available. This also keeps thelocation.hash auto-scroll path safe, since it calls throughcalculateScrollOffset().Drupal.behaviors.BSLibAnchorScroll.attach() returns early when the settings areStart within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
pivica commented