marcandre

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
  1. Is this expected / am I missing something?

  2. 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.

Showing Posts 1 to 6

wojtekmach

wojtekmach

Hex Core Team

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).

The combination of:

  1. Elixir v1.11 (separately tracks imports so these don’t become compile-time deps)
  2. plug_init_mode (What's new in Phoenix development - February 2018 - DockYard)
  3. explicit router helper aliases (ditto; also thanks to 1. should be less of an issue in general)

should hopefully have alleviated those issues. Have you already tried all three? If not, did it help at all?

plug_init_mode is 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

marcandre OP

Sorry, forgot to mention, this is

  1. using shiny new Elixir 1.12.1 + OTP 24
  2. plug_init_mode is set to :runtime in dev mode (and I wish I knew if it could be in test mode).
  3. probably not using explicit router help aliases. We probably should do that to avoid some recompilation when we change routes, but my understanding though is that there is no fundamental reason for the router to have a compile-time dependency on these layouts, right?

That mix xref graph --source lib/app_web/router.ex --label compile has refs to lib/app_web/plugs/ is fine, but lib/app_web/views/ is not.

marcandre

marcandre OP

Actually, my followup question is: I understand this better, but can I avoid it too?

marcandre

marcandre OP

Very surprising to me, but moving a plug module from pipe_through and by using an intermediary pipeline removes the compile-time dependency?!

Again, is that expected, where is that documented, and can’t this be improved?

$ mix xref graph --source lib/bobby_web/router.ex --label compile  | wc -l
      113
$ git stash pop && git diff

lib/bobby_web/router.ex
──────────────────────────────────┐
429: defmodule BobbyWeb.Router do │
──────────────────────────────────┘

+ pipeline :active_policies do
+   plug Plugs.ActivePolicies
+ end

  scope "/", BobbyWeb do
-   pipe_through([:browser, Plugs.ActivePolicies])
+   pipe_through([:browser, :active_policies])

$ mix xref graph --source lib/bobby_web/router.ex --label compile  | wc -l
     86
axelson

axelson

Scenic Core Team

For layout files I usually create a separate plug instead of calling :put_layout in the router:
https://github.com/thechangelog/changelog.com/pull/332

I’m surprised that an intermediary pipeline would change the compile-time dependencies.

marcandre

marcandre OP

Thanks. It’s cleaner than my “solution”, but more verbose.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews