Rename 'Blacklight' inside of core.js as 'Core' #3355
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When bundled into one file such as the 'blacklight.esm.js' being produced, it was resulting in a conflict with top-level Blacklight module, and resulting in error
'Uncaught TypeError: Blacklight.activate is not a function'
While Javascript modules are normally isolated namespaces and you wouldn't expect a conflict, something about how bundlers end up bundling them together means that when the onload callback is actually called (at runtime, after the bundle has been bundled), and tries to call
Blacklight
, it ends up refering to a different top-level 'Blacklight' module -- one that doens't have an 'activate' property, instead has 'Core', 'Modal', etc -- the default exports. Instead of capturing the local one under closure as desired.blacklight/app/javascript/blacklight/core.js
Lines 37 to 41 in 04e3cf0
The current produced 'blacklight.esm.js' file is not actually useable (also in BL8). This makes it useable again.
The problem is present in the produced ./app/assets/javascripts/blacklight/blacklight.esm.js file which this gem already produces (using rollup), and I think I also reproduced it with esbuild.
Renaming to const name to
Core
to avoid a conflict seems to resolve the problem -- and follows the pattern in all of the other module files.It should not cause a problem or be backwards incompatible for anyone else using ESM modules (including
importmap-rails
!), precisely because the names inside the module are supposed to be isolated inside the module, the exports are still the same and still used the same. In my manual tests it seemed to be good, and should also be demonstrated not causing a problem by tests being green here hopefully!I plan to backport this to BL8 if/once merged!