Skip to content

Commit c3a0f02

Browse files
wojtekmachjosevalim
authored andcommitted
Expand the plug only in plug_init_mode :runtime (#4394)
1 parent 36fbd7f commit c3a0f02

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/phoenix/controller/pipeline.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,12 @@ defmodule Phoenix.Controller.Pipeline do
180180
defmacro plug(plug, opts), do: plug(plug, opts, true, __CALLER__)
181181

182182
defp plug(plug, opts, guards, caller) do
183-
plug = Macro.expand(plug, %{caller | function: {:init, 1}})
183+
plug =
184+
if Phoenix.plug_init_mode() == :runtime do
185+
Macro.expand(plug, %{caller | function: {:init, 1}})
186+
else
187+
plug
188+
end
184189

185190
quote do
186191
@plugs {unquote(plug), unquote(opts), unquote(escape_guards(guards))}

lib/phoenix/router.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,12 @@ defmodule Phoenix.Router do
665665
See `pipeline/2` for more information.
666666
"""
667667
defmacro plug(plug, opts \\ []) do
668-
plug = Macro.expand(plug, %{__CALLER__ | function: {:init, 1}})
668+
plug =
669+
if Phoenix.plug_init_mode() == :runtime do
670+
Macro.expand(plug, %{__CALLER__ | function: {:init, 1}})
671+
else
672+
plug
673+
end
669674

670675
quote do
671676
if pipeline = @phoenix_pipeline do

0 commit comments

Comments
 (0)