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

With propshaft this gem creates a lot of assets during precompile #3657

Closed
4 of 11 tasks
jagthedrummer opened this issue Feb 11, 2025 · 7 comments · Fixed by #3671
Closed
4 of 11 tasks

With propshaft this gem creates a lot of assets during precompile #3657

jagthedrummer opened this issue Feb 11, 2025 · 7 comments · Fixed by #3671
Assignees

Comments

@jagthedrummer
Copy link

jagthedrummer commented Feb 11, 2025

Describe the bug

I'm working on switching the Bullet Train starter repo from sprockets to propshaft and I've found that the avo gem produces a lot of assets during precompilation.

Reproduction repository for the bug

The branch I'm working on: https://github.com/bullet-train-co/bullet_train/tree/jeremy/propshaft

The PR for that branch: bullet-train-co/bullet_train#1910

Steps to use in the reproduction repository

Remove or comment out these lines: https://github.com/bullet-train-co/bullet_train/blob/011a9e6327b4de8efbe5eb1d46a1e6c9c6ccb730/config/initializers/assets.rb#L8-L11

Run rails assets:precompile.

Then run tree public/assets/avo and tree pubic/assets/heroicons.

You'll see that there are a lot of .svg files in the avo and heroicons directories.

Expected behavior & Actual behavior

I would expect those files not to be there.

System configuration

Avo version: 3.17.2

Rails version: 8.0.1

Ruby version: 3.4.1

License type:

  • Community
  • Pro
  • Advanced

Are you using Avo monkey patches, overriding views or view components?

  • Yes. If so, please post code samples.
  • No

Screenshots or screen recordings

Here's a link to a gist showing the differences in public/assets after precompiling between sprockets and propshaft: https://gist.github.com/jagthedrummer/f38a0c00879fe34c795e0ff3fd152734

Additional context

I found that I can work around it by explicitly adding several avo directories to the assets.excluded_paths config.

Rails.application.config.assets.excluded_paths = [
  Avo::Engine.root.join("app/assets/builds"),
  Avo::Engine.root.join("app/assets/config"),
  Avo::Engine.root.join("app/assets/stylesheets"),
  Avo::Engine.root.join("app/assets/svgs")
]

I've done a little bit of testing after excluding these paths and things seem to be working as expected. It seems like avo is including a ton of .svg files that aren't actually used for anything.

Impact

  • High impact (It makes my app un-usable.)
  • Medium impact (I'm annoyed, but I'll live.)
  • Low impact (It's really a tiny thing that I could live with.)

Urgency

  • High urgency (I can't continue development without it.)
  • Medium urgency (I found a workaround, but I'd love to have it fixed.)
  • Low urgency (It can wait. I just wanted you to know about it.)
@adrianthedev
Copy link
Collaborator

I saw this issue @jagthedrummer.
We'll work on a fix for it this week 🙌

FYI, that was a pain in my but as well but was too lazy to fix it.

@adrianthedev adrianthedev moved this to Next up in Issues Feb 17, 2025
@adrianthedev
Copy link
Collaborator

adrianthedev commented Feb 17, 2025

Approach

  • create a new gem (avo-heroicons) with the heroicons svg files
  • this new gem becomes a dependency of Avo
  • the gem does not expose the svg paths to the asset pipeline (propshaft or sprockets), hence no logs
  • update our svg method to take that path into account and serve the assets

@Paul-Bob Paul-Bob self-assigned this Feb 17, 2025
@Paul-Bob Paul-Bob moved this from Next up to In Review in Issues Feb 17, 2025
@github-project-automation github-project-automation bot moved this from In Review to Done in Issues Feb 17, 2025
@jagthedrummer
Copy link
Author

Thanks for taking a look at this. I just updated to 3.17.7 and there are definitely fewer avo assets showing up in the precompiled output but there are still quite a few.

$ tree public/assets/avo
public/assets/avo
├── arrow-circle-right-3470a132.svg
├── arrow-down-3c7dcc10.svg
├── arrow-left-bdaee781.svg
├── arrow-up-6da965e7.svg
├── avocado-9b78bfb6.svg
├── badge-check-sm-8577c5d9.svg
├── bell-21605298.svg
├── check-circle-6aba65b6.svg
├── chevron-down-95e0dfd6.svg
├── chevron-right-372abaed.svg
├── chevron-up-7e09c03b.svg
├── code-cad7435e.svg
├── color-swatch-2f7cc9b9.svg
├── dashboards-aa0f0a11.svg
├── detach-7e4ef9b8.svg
├── document-text-08352a68.svg
├── download-ea871e45.svg
├── download-solid-3b3c9f49.svg
├── download-solid-reversed-5db9c1c7.svg
├── edit-137a2727.svg
├── editor-bold-4fb44e46.svg
├── editor-italic-8af19fbe.svg
├── editor-link-321b0a87.svg
├── editor-list-707d0ba0.svg
├── editor-ordered-list-2ed11567.svg
├── editor-strike-4417b2a1.svg
├── editor-underline-720ae53a.svg
├── exclamation-80ff0d8e.svg
├── exclamation-circle-sm-cadcb322.svg
├── exclamation-sm-982f844d.svg
├── eye-bea384e1.svg
├── failed_to_load-85ed125f.svg
├── filter-02053928.svg
├── fire-53625ffa.svg
├── font-8bccfb1b.svg
├── game-board-76ff1c3f.svg
├── globe-b5acbaf1.svg
├── grid-empty-state-e4702af2.svg
├── grid-view-type-9c10ad52.svg
├── information-circle-6e32732e.svg
├── information-circle-sm-d2f9a9f5.svg
├── library-03f130f8.svg
├── logout-375f2c9b.svg
├── map-empty-state-e4702af2.svg
├── map-view-type-55aaea06.svg
├── menu-638f230a.svg
├── menu-back-24c468f2.svg
├── photograph-fc76c4a1.svg
├── play-db77f5ef.svg
├── plus-46b81e14.svg
├── plus-circle-a56ac8e9.svg
├── question-mark-circle-ccacd750.svg
├── resources-6c524bad.svg
├── save-621d6c4d.svg
├── selector-ebffb0c4.svg
├── sort-ascending-d370078d.svg
├── sort-descending-c197a37f.svg
├── square-kanban-ac7c7fe9.svg
├── switch-horizontal-6205d289.svg
├── switch-vertical-0099c2ca.svg
├── table-empty-state-54479a65.svg
├── table-view-type-fb8ae544.svg
├── three-dots-badb5357.svg
├── thumbs-down-3704c5d7.svg
├── thumbs-up-6c3eee16.svg
├── times-b4973eaf.svg
├── tools-21015fba.svg
├── trash-88e4fddf.svg
├── trash-sm-af5f75b8.svg
├── triangle-up-a239398b.svg
├── user-circle-8c6cb2a6.svg
├── view-grid-9ec1d0fb.svg
├── view-grid-add-78c675cf.svg
├── view-list-c49c4fe7.svg
├── x-b4973eaf.svg
└── x-circle-d3bdfaef.svg

It looks like they're coming from here: https://github.com/avo-hq/avo/tree/main/app/assets/svgs/avo

Should this issue be reopened, or should we make a new one?

@adrianthedev adrianthedev reopened this Feb 18, 2025
@Paul-Bob
Copy link
Contributor

Hi @jagthedrummer

It looks like your solution with config.assets.excluded_paths is working as expected. Since Avo's SVG finder searches within the gem's root path and not public/assets, this should not cause any issues in production.


Propshaft makes all the assets from all the paths it's been configured with through config.assets.paths available for serving and will copy all of them into public/assets when precompiling.

Source https://github.com/rails/propshaft?tab=readme-ov-file#usage

config.assets.paths, by default, include all sub-directories from "app/assets"

You can however exempt directories that have been added through the config.assets.excluded_paths.

Source https://github.com/rails/propshaft?tab=readme-ov-file#usage


That said, we could configure this within Avo itself:

# lib/avo/engine.rb
module Avo
  class Engine < ::Rails::Engine
    config.assets.excluded_paths << Avo::Engine.root.join("app", "assets", "svgs")
  end
end

However, we’re not entirely sure if users rely on those SVGs from public in other parts of their applications. Introducing this change on our side could potentially break existing setups.


Our recomendation

For now, we suggest you explicitly add the Avo::Engine.root.join("app", "assets", "svgs") path to Rails.application.config.assets.excluded_paths.

Additionally, when modifying excluded_paths, we recommend using << instead of = to ensure that existing configurations from other engines remain intact:

Rails.application.config.assets.excluded_paths << [
  Avo::Engine.root.join("app/assets/svgs"),
  Cloudinary::Engine.root.join("vendor/assets/html"),
  Cloudinary::Engine.root.join("vendor/assets/javascripts"),
  Doorkeeper::Engine.root.join("vendor/assets/stylesheets"),
  BulletTrain::Themes::Light::Engine.root.join("app/assets/config"),
  BulletTrain::Themes::Light::Engine.root.join("app/assets/stylesheets"),
]

Let us know if you have any concerns,

Thank you!

@Paul-Bob Paul-Bob moved this from Done to In Progress in Issues Feb 18, 2025
@jagthedrummer
Copy link
Author

Hey @Paul-Bob, I guess I don't have any concerns so much as just a question: How are the svg assets that are still being precompiled different from the ones that were moved into avo-heroicons? Like why was it OK to move those other icons out of the default set, but it's not OK to move these?

Manually excluding them does work, so if that's the way we need to go that's fine. Might be nice to mention it in the installation docs so people are aware that it's something they may want to do.

@Paul-Bob
Copy link
Contributor

How are the svg assets that are still being precompiled different from the ones that were moved into avo-heroicons? Like why was it OK to move those other icons out of the default set, but it's not OK to move these?

avo-heroicons will be automated to ensure it always fetches the latest Heroicons version.

In contrast, the other SVG assets are custom Avo icons that we modify or add as needed. Extracting them into a separate gem would introduce unnecessary friction in development, as maintaining a separate package for every addition, deletion, or modification would be necessary.

Manually excluding them does work, so if that's the way we need to go that's fine.

I believe this is the best option for both of us at the moment, as it requires minimal effort on both your end and ours.

We have some ideas to explore regarding the assets pipeline and may revisit this issue in the future.

Might be nice to mention it in the installation docs so people are aware that it's something they may want to do.

Documenting it is a good idea, thank you for the suggestion.

@Paul-Bob
Copy link
Contributor

Closing this issue to maintain a tidy queue. Let’s keep the conversation going and reopen it if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants