Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default icon path detection for Rails asset pipelines #7585

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dbforge
Copy link

@dbforge dbforge commented May 26, 2021

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 of marker-icon.png. It also replaces the corresponding URL occurences in the stylesheet which define the default icon paths over styles. This breaks line 55 of src/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).

@IvanSanchez
Copy link
Member

Ok, so this is an attempt to fix a specific instance of the default icon path detection (#4968 / #7092 / #6496).

I'm... unsure about this. Generally, Leaflet tries to focus on vanilla JS only, so a fix for a specific build toolchain seems out of place. On the other hand, this change shouldn't break anything. So I'm conflicted on merging this.

(I wish we'd rather spend some time on #7203)

@dbforge
Copy link
Author

dbforge commented May 26, 2021

#7203 would also be a good alternative, I think.
In any case some change would be useful. Basically everybody who tries to use it in Rails (which is kind of comfortable due to the NPM package and yarn) must provide a custom module or else it will break the icons (unless you specify custom ones which I haven't explored any further).

I understand this fix is very specifically related to Rails' builde pipeline. Even though it doesn't break existing code, it might not come in very handy. Nevertheless, we'd somehow need a solution that doesn't break any build toolchains by default.

My current status is fine, I have a local leaflet package set up and don't have the deep urge to get an immediate change on this. Would just be a possible solution. You should focus on what you consider more important.

@Falke-Design Falke-Design added compatibility Cross-browser/device/environment compatibility needs discussion labels Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Cross-browser/device/environment compatibility needs discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants