Compile time warning from not passing required attributes to function component only shows consistently with mix compile --force

Hi, I am a beginner and have been following the Phoenix introduction step-by-step up to Components and HEEx — Phoenix v1.7.14 . I have noticed I only get the following compile time warning (from not passing required attributes to function component) consistently with mix compile --force.

[...]
warning: missing required attribute "messenger" for component HelloWeb.HelloHTML.greet/1
[...]

When I just do mix compile or mix phx.server I do not get the warning. Is this intended behavior? It seems surprising to me.

$ elixir --version
Erlang/OTP 25 [erts-13.2.2.10] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.17.2 (compiled with Erlang/OTP 25)

$ mix phx --version
Phoenix v1.7.14
2 Likes

If a file hasn’t changed since its last compilation, mix compile won’t do anything with it.

1 Like

Hi, thanks for your reply :slight_smile:

I should I have clarified that I get other warnings consistently, such as:

warning: HelloWeb.Admin.ReviewController.init/1 is undefined (module HelloWeb.Admin.ReviewController is not available or is yet to be defined)

So mix compile does something even though the files have not changed.

Is it intended behavior to make one warning show every time and another warning hidden on recompiles? Seems to me like a bug either in in my code, mix, or phoenix.

I believe this has been fixed. I tried to reproduce your behaviour on Livebook’s repository, added <.flash_group flash={@flash} omg={123} />, run mix compile, changed another unrelated file, ran mix compile, and the warning showed up both times. We are using Elixir v1.17 and LiveView 1.0 RC.

1 Like

Hi, I see the same (correct) behavior as you on the Livebook repository when I follow your steps. However, you introduce an unrelated change whereas I change nothing and expect that my warning will show up again.

I am also using Elixir v1.17 and LiveView 1.0 RC as far as I know but still encounter the ‘bug’. Here is an excerpt from the LiveView entry in mix.lock:

 "phoenix_live_view": {:hex, :phoenix_live_view, "1.0.0-rc.6" [...]

(I assume that means I am using that version, but I could of course be making some beginner mistake here).

Here is a wall text with my steps (I see the same in the Livebook repository):

  1. Start from a clean working tree
$ git status
On branch master
nothing to commit, working tree clean
  1. Mix compile and see warnings about undefined modules
$ mix compile
warning: HelloWeb.Admin.ReviewController.init/1 is undefined (module HelloWeb.Admin.ReviewController is not available or is yet to be defined)
[...]
  1. Introduce mistake
$ git diff
diff --git a/lib/hello_web/controllers/hello_html/show.html.heex b/lib/hello_web/controllers/hello_html/show.html.heex
index 8664643..c0b6f5d 100644
--- a/lib/hello_web/controllers/hello_html/show.html.heex
+++ b/lib/hello_web/controllers/hello_html/show.html.heex
@@ -1,5 +1,5 @@
 <section>
-<.greet messenger={@messenger}/>
+<.greet messenger={@messenger} omg={123}/>
 <%= if true do %>
     <p>true</p>
 <% else %>
  1. Mix compile and see warning about mistake and undefined modules
$ mix compile
Compiling 1 file (.ex)
    warning: undefined attribute "omg" for component HelloWeb.HelloHTML.greet/1
[...]
  1. Mix complie again and see no warning about mistake, only about undefined modules
$ mix compile
    warning: HelloWeb.Admin.ReviewController.init/1 is undefined (module HelloWeb.Admin.ReviewController is not available or is yet to be defined)
[...]

Please let me know if and how I can provide any more information to help track this down.
Note that I am an Elixir beginner, so I probably need more explicit guidance than usual about Elixir-specifics.

1 Like

Got it, I can reproduce it. I will work on a fix later. :slight_smile:

2 Likes

Store warnings emitted from external resources · elixir-lang/elixir@2f84c1e · GitHub :slight_smile: Thanks for the report!

4 Likes