marcandre
I’m fighting against a mess of compile dependencies.
One issue is that many things have a runtime dependency on the router (ok) and that the router has multiple compile-time dependencies on views and layouts (not ok).
I notice that changing the modules of these views to Module.concat solves the problem:
# router.ex
# introduces a compile-time dependency
pipeline :example do
plug(:put_layout, {MyApp.LayoutView, :example})
end
# no dependency
pipeline :example do
plug(:put_layout, {Module.concat(:MyApp, :LayoutView), :example})
end
-
Is this expected / am I missing something?
-
Before I write a macro to do this, is there a better way to resolve this?
This kind of issue does not seem unique.
I was naively thinking that this pattern was pretty natural and would be handled properly, either by put_layout accepting a string for the module name, or by plug being a smart macro that could avoid the compile-time dependency altogether, or by pipelines being in a different files from routes for example.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
wojtekmach
The combination of:
plug_init_mode(What's new in Phoenix development - February 2018 - DockYard)should hopefully have alleviated those issues. Have you already tried all three? If not, did it help at all?
plug_init_modeis only added to config/dev.exs by default which means when running tests we’d potentially have more recompilations than in dev, perhaps we should be adding it to test.exs too, not sure.marcandre
Sorry, forgot to mention, this is
plug_init_modeis set to:runtimein dev mode (and I wish I knew if it could be in test mode).That
mix xref graph --source lib/app_web/router.ex --label compilehas refs tolib/app_web/plugs/is fine, butlib/app_web/views/is not.marcandre
Actually, my followup question is: I understand this better, but can I avoid it too?
marcandre
Very surprising to me, but moving a plug module from
pipe_throughand by using an intermediarypipelineremoves the compile-time dependency?!Again, is that expected, where is that documented, and can’t this be improved?
axelson
For layout files I usually create a separate plug instead of calling
:put_layoutin the router:https://github.com/thechangelog/changelog.com/pull/332
I’m surprised that an intermediary pipeline would change the compile-time dependencies.
marcandre
Thanks. It’s cleaner than my “solution”, but more verbose.