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

replace leaflet files from assets.rb in questionRich.html and _mapDependencies.html #7945

Merged
merged 3 commits into from
Aug 18, 2020

Conversation

Tlazypanda
Copy link
Collaborator

@Tlazypanda Tlazypanda commented May 22, 2020

Fixes #7922
Replace leaflet files which are already present in asset pipeline by using javascript_include_tag and stylesheet_link_tag. Also removed files which are already served from application.js and application.css. Added some files to assets.rb for precompilation as well.

Edited _mapDependencies as well since some files there also needed to be replaced and in testing inorder to reduce js execution time.

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

Screenshots

Before

7945_before

After

7945_after

Thanks!

@Tlazypanda Tlazypanda requested a review from a team as a code owner May 22, 2020 22:48
@codecov
Copy link

codecov bot commented May 22, 2020

Codecov Report

Merging #7945 into main will decrease coverage by 0.88%.
The diff coverage is 71.19%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7945      +/-   ##
==========================================
- Coverage   82.17%   81.28%   -0.89%     
==========================================
  Files         100      101       +1     
  Lines        5772     5872     +100     
==========================================
+ Hits         4743     4773      +30     
- Misses       1029     1099      +70     
Impacted Files Coverage Δ
app/controllers/home_controller.rb 98.38% <ø> (ø)
app/controllers/users_controller.rb 81.11% <ø> (-1.19%) ⬇️
app/mailers/admin_mailer.rb 90.90% <0.00%> (ø)
app/models/concerns/statistics.rb 96.72% <ø> (ø)
app/controllers/spam2_controller.rb 61.53% <58.90%> (-38.47%) ⬇️
app/controllers/batch_controller.rb 67.96% <67.96%> (ø)
app/models/user.rb 87.68% <77.77%> (+1.23%) ⬆️
app/controllers/notes_controller.rb 83.40% <83.33%> (-0.01%) ⬇️
app/models/comment.rb 77.51% <83.33%> (+0.62%) ⬆️
app/controllers/wiki_controller.rb 85.34% <92.30%> (+0.34%) ⬆️
... and 32 more

@Tlazypanda
Copy link
Collaborator Author

@jywarren @cesswairimu Should we add the remaining files of /lib mentioned in this file for precompilation by augmenting the assets.rb array? Thanks ✌️

@Tlazypanda
Copy link
Collaborator Author

Hey @jywarren @cesswairimu @emilyashley Looking forward to your input on this 😄

@Tlazypanda Tlazypanda force-pushed the leaflet_questionRich_script branch from edff18e to 63014c5 Compare May 27, 2020 19:02
@Tlazypanda Tlazypanda changed the title WIP: replace leaflet files from assets.rb in questionRich.html replace leaflet files from assets.rb in questionRich.html May 27, 2020
@Tlazypanda Tlazypanda changed the title replace leaflet files from assets.rb in questionRich.html WIP: replace leaflet files from assets.rb in questionRich.html and _mapDependencies.html May 27, 2020
@Tlazypanda Tlazypanda changed the title WIP: replace leaflet files from assets.rb in questionRich.html and _mapDependencies.html replace leaflet files from assets.rb in questionRich.html and _mapDependencies.html May 27, 2020
@Tlazypanda Tlazypanda closed this May 27, 2020
@Tlazypanda Tlazypanda reopened this May 27, 2020
@Tlazypanda
Copy link
Collaborator Author

@VladimirMikulic can you help me with the travis tests failure? Thanks ✌️

@VladimirMikulic
Copy link
Contributor

Hi @Tlazypanda. The error in Travis tells us that the route /assets/images/layers.png doesn't exist.
Leaflet lib is using those layers. You've probably removed the wrong asset. leaflet.js maybe?

@Tlazypanda
Copy link
Collaborator Author

Hmm..weird I removed those assets which would otherwise be available from the asset pipeline @VladimirMikulic leaflet.js is in application.js then shouldn't it be present in the asset pipeline already bundled in application.js 😅

@VladimirMikulic VladimirMikulic requested a review from Uzay-G May 31, 2020 17:15
@jywarren
Copy link
Member

jywarren commented Jun 2, 2020

I believe layer.png often causes issues in the asset pipeline, actually! Maybe this helps? #2537

But i recall this kind of thing with Leaflet image assets, esp. those referred to in CSS, because CSS doesn't respect asset pipeline routing (i think that's right!). So it could be worth a broader search for leaflet layers.png asset pipeline -- maybe on the Leaflet repo or StackOverflow?

Good luck, this looks great and thanks to both of you!

@Tlazypanda
Copy link
Collaborator Author

@jywarren Found the issue! So basically whenever we are trying to move this into the asset pipeline it is searching in the route assets/images for the css images but in the link form it is searching in the node_modules folder where the css file is ...so a fix would be to move the layers.png file to assets/images but I am not sure if I should proceed with it ...what are your thoughts on this? Thanks ✌️

@Tlazypanda
Copy link
Collaborator Author

Hey @cesswairimu @jywarren any update on what should be my course of action 😅 Thanks ✌️

@jywarren
Copy link
Member

OK this could be linked to #5095 (comment) -- is that right?

For the broader question, originally we included assets in the editor because we thought it optimal to only include them here, instead of on any page (the editor has an especially large number of assets, not needed elsewhere on the site). But I totally trust your judgement and analysis of whether re-organizing which assets are loaded where and how they're minified, so as long as nothing breaks 😅 please go for it! Thank you!!!

@Tlazypanda Tlazypanda force-pushed the leaflet_questionRich_script branch from 63014c5 to 23d903a Compare June 29, 2020 06:53
@Tlazypanda
Copy link
Collaborator Author

Hey @jywarren @cesswairimu I am also fairly confused as to what can be done here 😅 The reason being if I am supposed to reference the images without adding them to assets/images route then I will have to add the path of the specific images dir to the config.assets.path but the issue with this is that I will have to reference the image css with image_url(image.png) but since this is an external library I can't change its code. Maybe we can remove the css file from the asset pipeline to prevent adding these static images for precompilation?

https://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets
https://makandracards.com/makandra/29567-managing-vendor-libraries-with-the-rails-asset-pipeline

@Tlazypanda Tlazypanda force-pushed the leaflet_questionRich_script branch 2 times, most recently from b61f8dd to dddfda3 Compare June 29, 2020 08:09
@Tlazypanda Tlazypanda force-pushed the leaflet_questionRich_script branch from 3568a35 to ad8881f Compare June 29, 2020 08:18
@Tlazypanda
Copy link
Collaborator Author

@cesswairimu @jywarren can you kindly review? Thanks ✌️

@cesswairimu
Copy link
Collaborator

@Tlazypanda quick question...are the contents of the files in /assets identical to the ones in /lib?

@Tlazypanda
Copy link
Collaborator Author

Tlazypanda commented Jun 30, 2020

Hey @cesswairimu I am not sure I completely follow 😅 on precompilation all are put together in assets directory but since here we are referencing image from css we need to add relative path so since this is an external lib and we can't make changes to the code (since it is yarn package) so I removed the file that required the css leaflet.css (as you can see in _mapDependencies now it is referenced from /lib suggesting that is not part of asset pipeline)

The scripts removed are already present in the application.js

@cesswairimu
Copy link
Collaborator

cesswairimu commented Jun 30, 2020

aha! gotcha thanks 👍

@jywarren jywarren changed the base branch from master to main June 30, 2020 18:17
@Tlazypanda Tlazypanda closed this Jul 7, 2020
@Tlazypanda Tlazypanda reopened this Jul 7, 2020
Copy link
Contributor

@sagarpreet-chadha sagarpreet-chadha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am approving it but maybe you might want to do this change in follow up PR or here only. No worries, thanks 😄

@@ -5,21 +5,15 @@
<link href="/lib/publiclab-editor/dist/PublicLab.Editor.css" rel="stylesheet">

<!-- required for MapModule -->
<link href="/lib/leaflet/dist/leaflet.css" rel="stylesheet">
<script src="/lib/leaflet/dist/leaflet.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep this and remove from application level, because as you are also working on performance improvement, having a light entry page should take less time, right?
When these libraries are required they should be loaded only then (lazy loading), what do you think?
😄 🎉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Tlazypanda any comment on these last questions from @sagarpreet-chadha ? My apologies for replying late to these. Thank you!!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jywarren @sagarpreet-chadha I totally missed this 😅 my apologies ...ummm can we do this in a follow up pr because I think the leaflet.js and css files are actually required on many routes since the map is loaded on dashboard/user profile/all editor pages/map routes etc so might have to investigate it more to make sure that removing it won't break anything. What do you think? Thanks ✌️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's totally fine. Always game to split up PRs! Does that make this PR otherwise good to merge? Thank you!

@jywarren
Copy link
Member

Retriggering once more!

@jywarren jywarren merged commit 7fbddc3 into publiclab:main Aug 18, 2020
@jywarren
Copy link
Member

Great work, @Tlazypanda !!!

nadimakhtar97 pushed a commit to nadimakhtar97/plots2 that referenced this pull request Sep 21, 2020
shubhangikori pushed a commit to shubhangikori/plots2 that referenced this pull request Oct 12, 2020
alvesitalo pushed a commit to alvesitalo/plots2 that referenced this pull request Oct 14, 2020
piyushswain pushed a commit to piyushswain/plots2 that referenced this pull request Oct 22, 2020
manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
ampwang pushed a commit to ampwang/plots2 that referenced this pull request Oct 26, 2021
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace leaflet files in app/views/editor/questionRich.html.erb
5 participants