Problem/Motivation
When attempting to add a dropdown to the navbar in a Drupal site, a JavaScript error occurs, preventing the dropdown from functioning correctly. The error message indicates that the createPopper function from the Popper.js library is not recognized, leading to a TypeError.
Uncaught TypeError: Popper__namespace.createPopper is not a function
at Dropdown._createPopper (dropdown.js?showaf:220:40)
at Dropdown.show (dropdown.js?showaf:137:12)
at Dropdown.toggle (dropdown.js?showaf:124:51)
at HTMLButtonElement.<anonymous> (dropdown.js?showaf:390:40)
at HTMLDocument.handler (event-handler.js?showaf:75:21)
The Responsive Theme Preview module is loading its Popper.js library
dropdown.jsandtooltip.jsare allocating the library by@popperjs/coreNot by it’s physical file location and name space.
@popperjs/core@2.9.2is working but2.11.8is not
- Add a dropdown menu to the navbar in your Drupal site.
- Ensure that the dropdown.js file is included and that Popper.js is supposed to be loaded.
- Attempt to toggle the dropdown menu by clicking on it.
- Observe the JavaScript console for the error message mentioned above.
Proposed resolution
#3471477: Fix Popper.js Error When Adding Navbar Dropdown in Varbase Components
Add aBootstrap Fixer
Add custom Bootstrap fixes and changes over the default provided
Bootstrap 5.3.3 package.
Using UMD in Varbase Components and Vartheme BS5
The UMD format in Bootstrap is using ESM format.
`dropdown.js` and `tooltip.js` are allocating the library by `@popperjs/core`
- Add Popper global namespace fixer for the `dropdown.js` file in Bootstrap.
- Add Popper global namespace fixer for the `tooltip.js` file in Bootstrap.
- Drop the Popper.js library file from the Responsive Theme preview module. Varbase Components and Vartheme BS5 are providing that using Node.js with Bootstrap 5.
Remaining tasks
- ✅ File an issue about this project
- ✅ Addition/Change/Update/Fix to this project
- ✅ Testing to ensure no regression
- ➖ Automated unit/functional testing coverage
- ➖ Developer Documentation support on feature change/addition
- ➖ User Guide Documentation support on feature change/addition
- ✅ UX/UI designer responsibilities
- ✅ Accessibility and Readability
- ✅ Code review from 1 Varbase core team member
- ✅ Full testing and approval
- ✅ Credit contributors
- ✅ Review with the product owner
- ✅ Update Release Notes and Update Helper on new feature change/addition
- ✅ Release varbase-10.0.2, vartheme_bs5-3.0.3
Varbase update type
- ✅ No Update
- ➖ Optional Update
- ➖ Forced Update
- ➖ Forced Update if Unchanged
User interface changes
- N/A
API changes
- N/A
Data model changes
- N/A
Release notes snippet
- Issue #3469222 by ahmad khader, mohammedodeh: Fixed Popper.js Error When Adding Navbar Dropdown in Vartheme BS5
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | popper_js_error_when_adding_navbar_dropdown-3469222-15.patch | 1.26 KB | ahmad khader |
Comments
Comment #2
rajab natshahComment #3
rajab natshahI confirm the issue
Which version of Varbase or its components (Varbase 10.0.x-dev development, the latest release, Varbase Components, or Vartheme BS5) are you facing this issue with?
How did the issue develop after the changes in #3456935: Fix dropdown menu limited to only two levels? Could you describe what happened?
#3456935 was committed, but not released yet.
Comment #4
mohammedodeh commentedI'm using Varbase 10.0.x-dev, Varbase Components version 2.0.2+1-dev, and Vartheme BS5 version 3.0.0-rc1+1-dev.
I don't believe the issue is related to the changes from #3456935: Fix dropdown menu limited to only two levels, as the problem persists regardless of that patch.
Comment #5
rajab natshahThanks, Odeh, for reporting.
I faced the issue in https://www.drupal.org/project/varbase_components/issues/3456935#comment...
Noted;
Let us have this fixed with a merge request.
Maybe in both Varbase Components and Vartheme BS5
Comment #6
rajab natshahComment #7
rajab natshahComment #8
rajab natshahComment #9
rajab natshahComment #10
rajab natshahProgress findings:
The Responsive Theme Preview module is loading its Popper.js library
dropdown.jsandtooltip.jsare allocating the library by@popperjs/coreNot by it’s physical file location and name space.
@popperjs/core@2.9.2is working but 2.11.8 is notBootstrap 5.3.3 is using
"@popperjs/core": "^2.11.8",https://github.com/twbs/bootstrap/blob/main/package.json#L110C5-L110C33
esm(works with import syntax )umd(works withtags or RequireJS)
cjs(works with require() syntax)Comment #11
rajab natshahComment #12
ahmad khader commentedhi @rajab_natshah
I have switched to bootstrap.bundle.min.js in my projects due to this error, along with other issues related to Bootstrap components. You can read more about it here: https://stackoverflow.com/questions/68750341/bootstrap-5-uncaught-typeer....
However, if you prefer to resolve the issue without transitioning to the bundled version, you must modify the global property from global["@popperjs/core"] to global. Popper in dropdown.js. This adjustment is necessary as it addresses the underlying issue. It is essential to ensure that the global properties are correctly defined and accessible. Utilizing string-based property access (global["@popperjs/core"]) is less common and may lead to complications if the global object properties are not configured as anticipated.
Comment #13
rajab natshahUsing
bootstrap.bundle.min.jswill definitely fix the issue.But that is not the right way.
That will work if you did this in projects ), but not as it was designed and structured for!!
As we work with SDC - it was requested by Razem ( not to load duplicate libraries, - or not to load extra not-needed JS in components )
This is a step toward moving our work with SDC with React Components.
~5.3.0JavaScript libraries to Single Directory Components (SDC) in Varbase ComponentsWe must find a way to make this work, maybe compile js files in our way.
Comment #14
rajab natshahNOTICE: The Responsive Theme Preview module is loading its
Popper.jslibrary. ( @popperjs/core v2.11.6 )It is using an old version of popper .. not the 2.11.8 one with Bootstrap 5.3.3
Comment #15
ahmad khader commented@rajab_natshah,
Hmmm, It's differently an issue but I think it's unrelated to this error since disabling the Responsive Theme Preview module won't fix the error.
I added a patch to test global object properties fix.
Comment #16
rajab natshahThat will work for ones, but when we update bootstrap?
it is a nodejs package too ( not a composer one )
The right way to do this is in the webpack.config.init.js
a JS script to re-compile, string manipulate the
dropdown.jsandtooltip.jsas in this comment
This will allow this to work in Vartheme BS5 and any custom generated cloned theme
we need a commend for updates .. like
drush updbbut it could be something likedrush var-update-theme mythemeNow the command to do this is
yarn theme:initI will continue with your fix idea .. but in the webpack.config.init.js file
Comment #17
rajab natshahComment #18
rajab natshahComment #19
rajab natshahComment #21
rajab natshah#3471477: Fix Popper.js Error When Adding Navbar Dropdown in Varbase Components
Comment #22
rajab natshahSteps to follow to run the Bootstrap Fixer in old projects
Open the terminal and change directory to the custom theme
Get the Bootstrap Fixer file.
Change
"theme:init"in package.json to"theme:init": "webpack --progress --config webpack.config.init.js ; node bootstrap.fixer.js",Add
"bootstrap:fixer": "node bootstrap.fixer.js",to"scripts"in the package.json file.The package.json file should look as in this link
run the following:
Comment #23
rajab natshahComment #24
rajab natshahComment #25
rajab natshahComment #26
rajab natshah✅ Released vartheme_bs5-3.0.3
Comment #28
rajab natshah✅ Released varbase-10.0.2