phoenixframework / phoenix

Peace of mind from prototype to production
https://www.phoenixframework.org
MIT License
21.3k stars 2.87k forks source link

New templates only work after deleting `_build` and recompiling in version `1.6.15` #5061

Closed lycheese closed 1 year ago

lycheese commented 1 year ago

Environment

Expected behavior

Following the Request life-cycle guide templates are found and recompiled automatically when adding them to lib/templates.

Actual behavior

Phoenix.Template.UndefinedError is thrown and the new template is only rendered correctly after stopping the server, deleting _build and starting the server again.

Trace ``` [info] GET /hello [debug] Processing with HelloWeb.HelloController.index/2 Parameters: %{} Pipelines: [:browser] [info] Sent 500 in 5ms [error] #PID<0.859.0> running HelloWeb.Endpoint (connection #PID<0.720.0>, stream id 19) terminated Server: localhost:4000 (http) Request: GET /hello ** (exit) an exception was raised: ** (Phoenix.Template.UndefinedError) Could not render "index.html" for HelloWeb.HelloView, please define a matching clause for render/2 or define a template at "lib/hello_web/templates/hello/*". No templates were compiled for this module. Assigns: %{conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{layout: {HelloWeb.LayoutView, "app.html"}}, body_params: %{}, cookies: %{"CSRF-Token-EIF7A" => "GeYkLmLwX3Nw6hbvbPY32UGFQc4pMyHG", "_hello_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYYWpDazdLdzB6OGpVUDFMLXA2aDJMaktx.un4wguFxE8wrsOqUqQBeJFd8BAKzLHEy2mXNbyH1LEI", "_hello_phx_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYQVJ5R0J4WlpnWHB4TVJOVmVWQWdFeE9l.TXIm30HuRzzLkLFSQN5o-Z3GiuPsGKl6mO817Vd041c", "_issue_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYVGtNRTVBQkpBX1dRMVpMUkF0YnlnR2Nw.D--pkmnKVF_Bw22SrtPbRodgwQxiPCxV0XxjBpd_Ay8"}, halted: false, host: "localhost", method: "GET", owner: #PID<0.859.0>, params: %{}, path_info: ["hello"], path_params: %{}, port: 4000, private: %{HelloWeb.Router => {[], %{Plug.Swoosh.MailboxPreview => ["mailbox"]}}, :before_send => [#Function<0.20795500/1 in Plug.CSRFProtection.call/2>, #Function<2.36663997/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.84243074/1 in Plug.Session.before_send/2>, #Function<0.11807388/1 in Plug.Telemetry.call/2>, #Function<1.86886788/1 in Phoenix.LiveReloader.before_send_inject_reloader/3>], :phoenix_action => :index, :phoenix_controller => HelloWeb.HelloController, :phoenix_endpoint => HelloWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {HelloWeb.LayoutView, :app}, :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_root_layout => {HelloWeb.LayoutView, :root}, :phoenix_router => HelloWeb.Router, :phoenix_template => "index.html", :phoenix_view => HelloWeb.HelloView, :plug_session => %{"_csrf_token" => "ajCk7Kw0z8jUP1L-p6h2LjKq"}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{"CSRF-Token-EIF7A" => "GeYkLmLwX3Nw6hbvbPY32UGFQc4pMyHG", "_hello_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYYWpDazdLdzB6OGpVUDFMLXA2aDJMaktx.un4wguFxE8wrsOqUqQBeJFd8BAKzLHEy2mXNbyH1LEI", "_hello_phx_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYQVJ5R0J4WlpnWHB4TVJOVmVWQWdFeE9l.TXIm30HuRzzLkLFSQN5o-Z3GiuPsGKl6mO817Vd041c", "_issue_key" => "SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYVGtNRTVBQkpBX1dRMVpMUkF0YnlnR2Nw.D--pkmnKVF_Bw22SrtPbRodgwQxiPCxV0XxjBpd_Ay8"}, req_headers: [{"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "en-US,en;q=0.5"}, {"connection", "keep-alive"}, {"cookie", "CSRF-Token-EIF7A=GeYkLmLwX3Nw6hbvbPY32UGFQc4pMyHG; _hello_phx_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYQVJ5R0J4WlpnWHB4TVJOVmVWQWdFeE9l.TXIm30HuRzzLkLFSQN5o-Z3GiuPsGKl6mO817Vd041c; _hello_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYYWpDazdLdzB6OGpVUDFMLXA2aDJMaktx.un4wguFxE8wrsOqUqQBeJFd8BAKzLHEy2mXNbyH1LEI; _issue_key=SFMyNTY.g3QAAAABbQAAAAtfY3NyZl90b2tlbm0AAAAYVGtNRTVBQkpBX1dRMVpMUkF0YnlnR2Nw.D--pkmnKVF_Bw22SrtPbRodgwQxiPCxV0XxjBpd_Ay8"}, {"dnt", "1"}, {"host", "localhost:4000"}, {"sec-fetch-dest", "document"}, {"sec-fetch-mode", "navigate"}, {"sec-fetch-site", "cross-site"}, {"sec-gpc", "1"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (X11; Linux x86_64; rv:105.0) Gecko/20100101 Firefox/105.0"}], request_path: "/hello", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "FyJ9AkHOPoCWCEUAAAWI"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}, {"x-download-options", "noopen"}, {"x-permitted-cross-domain-policies", "none"}, {"cross-origin-window-policy", "deny"}], scheme: :http, script_name: [], secret_key_base: :..., state: :unset, status: nil}} Assigned keys: [:conn] (phoenix_view 2.0.1) lib/phoenix_view.ex:672: Phoenix.View.__not_found__!/3 (phoenix_view 2.0.1) lib/phoenix_view.ex:379: Phoenix.View.render_within/3 (phoenix 1.6.15) lib/phoenix/controller.ex:784: Phoenix.Controller.render_with_layouts/5 (phoenix 1.6.15) lib/phoenix/controller.ex:772: Phoenix.Controller.render_and_send/4 (hello 0.1.0) lib/hello_web/controllers/hello_controller.ex:1: HelloWeb.HelloController.action/2 (hello 0.1.0) lib/hello_web/controllers/hello_controller.ex:1: HelloWeb.HelloController.phoenix_controller_pipeline/2 (phoenix 1.6.15) lib/phoenix/router.ex:354: Phoenix.Router.__call__/2 (hello 0.1.0) lib/hello_web/endpoint.ex:1: HelloWeb.Endpoint.plug_builder_call/2 (hello 0.1.0) lib/plug/debugger.ex:136: HelloWeb.Endpoint."call (overridable 3)"/2 (hello 0.1.0) lib/hello_web/endpoint.ex:1: HelloWeb.Endpoint.call/2 (phoenix 1.6.15) lib/phoenix/endpoint/cowboy2_handler.ex:54: Phoenix.Endpoint.Cowboy2Handler.init/4 (cowboy 2.9.0) /home/lycheese/local-dev/elixir/hello/deps/cowboy/src/cowboy_handler.erl:37: :cowboy_handler.execute/2 (cowboy 2.9.0) /home/lycheese/local-dev/elixir/hello/deps/cowboy/src/cowboy_stream_h.erl:306: :cowboy_stream_h.execute/3 (cowboy 2.9.0) /home/lycheese/local-dev/elixir/hello/deps/cowboy/src/cowboy_stream_h.erl:295: :cowboy_stream_h.request_process/3 (stdlib 4.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3 ```

Steps to reproduce

  1. mix phx.new hello
  2. cd hello
  3. mix ecto.create
  4. mix phx.server
  5. Check that localhost:4000/ renders
  6. Add code as described in the guide (repo link)
  7. Notice [debug] Live reload: lib/hello_web/templates/hello/index.html.heex in the terminal
  8. Navigate to localhost:4000/hello in the browser and get the error
  9. Stop the server and delete _build (restarting the server alone does not work)
  10. Start the server
  11. localhost:4000/hello renders without error

To check for file permissions problems I ran File.read("lib/hello_web/templates/hello/index.html.heex") and it returned successfully.


Edit: I just tried it with Phoenix 1.6.14 and this does not occur in that version.

Edit 2: I just tried master and was able to make it render new templates with hot-reloading.

dnzk commented 1 year ago

Having the same issue in my environment:

Following the Requst life cycle guide and when adding new page and revisiting that page I keep getting this error:

Could not render "see.html" for HelloWeb.HelloView, please define a matching clause for render/2 or define a template at "lib/hello_web/templates/hello/*". The following templates were compiled:

Until I delete the _build directory and restart the server.

wktdev commented 1 year ago

Similar problem here.

 Elixir version: Elixir 1.14.0
 Phoenix version: 1.6.13
 Operating system: MacOS Monterey 12.6

I received the same error as dnzk but I "fixed" it by deleting template contents and repasting them.

itsmonterey commented 1 year ago

Same issue here Elixir v1.12.2 Phoenix v1.6.15 OS Linux Ubuntu 22.04.1 LTS

Error

Request: GET /users/1
** (exit) an exception was raised:
    ** (Phoenix.Template.UndefinedError) Could not render "show.html" for RumblWeb.UserView, please define a matching clause for render/2 or define a template at "lib/rumbl_web/templates/user/*". The following templates were compiled:

* index.html

I had to run mix deps.clean --all and mix deps.get every time I got this error before it finally rendered successfully

minton commented 1 year ago

You can run mix compile --force in another terminal window to get it to pick up new templates.

josevalim commented 1 year ago

Fixed in PhoenixView 2.0.2. :)