-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Phoenix 1.7 Controller.put_layout @spec does not allow 1.6 usage #5320
Comments
Intentional. Consider it an early deprecation warning powered by Dialyzer. :) |
Unless I'm missing something does this change means anyone that uses Dialyzer can no longer use |
You can use Phoenix.View and you can still set layouts. That's not the problem here. The old style still works and, if you want to avoid the Dialyzer warning (which does not stop the code from executing), it is a matter of replacing this:
by this:
|
This was not a drop-in replacement for me, as it seems to require that you are also using the new-style layouts:
If I use the new atom syntax However, the old syntax works fine. What I did was write a hack to hide it from dialyzer, until we have time to migrate properly: @spec put_layout_workaround(Plug.Conn.t(), {atom(), String.t()}) :: Plug.Conn.t()
def put_layout_workaround(conn, arg) do
# credo:disable-for-next-line Credo.Check.Refactor.Apply
apply(Phoenix.Controller, :put_layout, [conn, arg])
end Then plug :put_layout_workaround, {ExampleWeb.LayoutView, "custom.html"} |
@adamu yeah I got the same exception trying the code @josevalim is suggesting. Your hack to get around dialyzer looks like it will be necessary as the new style does seem to require you to migrate your app which we just don't have time for in one go and don't want to get left behind. |
Hrm, this is not supposed to happen. Can you folks please provide a custom app that reproduces the error? Then I will take a look at it immediately. :) PS: @adamu my kid was very happy to see a Minecraft something (your avatar I believe) at his dad work computer :D |
Haha, I made that avatar way back in 2012 or so. It's been a while since I actually played :) I've made a reproduction of the issue in a dummy project here: # ---------------------------------------------------------------
# Working
plug :put_layout, {PutLayoutReproWeb.LayoutView, "custom.html"}
# Fails to compile
# plug :put_layout, html: {PutLayoutReproWeb.LayoutView, "custom.html"}
# Uses App layout
# plug :put_layout, html: {PutLayoutReproWeb.LayoutView, :custom}
# --------------------------------------------------------------- |
Thank you so much! ❤️ I pushed a warning that hopefully clarifies the situation. TL;DR: change your :controller to do:
|
I have upgraded from Phoenix 1.6 to Phoenix 1.7 with minimal code changes, but I am having issues due to the the non-backwards compatible
@spec
change to put_layout:phoenix/lib/phoenix/controller.ex
Lines 617 to 618 in a9ed59b
Although
put_layout
still accepts the 1.6 usage, the@spec
does not. As a result, this line:Fails dialyzer checks with the following error, even though the code works.
Is this intentional, or could the
| layout
be restored to allow the@spec
to match the behaviour?The text was updated successfully, but these errors were encountered: