Fix default icon path detection for Rails asset pipelines #7585
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.
In Rails applications you would usually use the asset pipeline or the webpacker gem for bundling assets together. As all assets are fingerprinted with a SHA hash to enable effective caching, which results in output files that are named differently than in the project structure. This also applies to image files. When importing/requiring leaflet over yarn (npm), the bundling process also affects the default icon files in
dist/images
as these also need to be imported due to the reference in the stylesheet. Webpacker then adds the fingerprint to the filename, resulting in e.g.marker-icon-2273e3d8.png
instead ofmarker-icon.png
. It also replaces the corresponding URL occurences in the stylesheet which define the default icon paths over styles. This breaks line 55 ofsrc/layer/marker/Icon.Default.js
because the RegExp replaces the hardcoded filename with an empty string. In case of a fingerprinted file, it consequently doesn't match, leading to a broken path which errors in the console.The fix introduces support for Webpacker and the Rails asset pipeline (Sprockets) without breaking the detection of the initial filename (without any fingerprints).