phoenixframework / phoenix_live_reload

Provides live-reload functionality for Phoenix
MIT License
317 stars 90 forks source link

Live reload doesn't work on Ubuntu using NeoVim #70

Closed DavidVII closed 6 years ago

DavidVII commented 6 years ago

This seems strange to me, but it appears that saving a template file using NeoVim causes the app to throw a Phoenix.Template.UndefinedError exception. I make the exact same changes using VSCode or a plain text editor and the live reload functionality works as expected.

I installed the inotify tools as mentioned in the installation guides and ran neovim without an init.vim file as to not use any config or plugins.

Here are the steps I took:

mix phx.new lab
Fetch and install dependencies? [Yn]

cd lab && mix ecto.create && mix phx.server

nvim lib/lab_web/templates/layout/app.html.eex

I add the word Hello right under the opening body tag and hit :w in neovim.

Browser refreshes in the background with this error.

[debug] Live reload: lib/lab_web/templates/layout/app.html.eex
[debug] Live reload: lib/lab_web/views/layout_view.ex
Compiling 1 file (.ex)
[debug] Live reload: lib/lab_web/templates/layout/app.html.eex
[debug] Live reload: lib/lab_web/templates/layout/app.html.eex
[info] GET /
[debug] Processing with LabWeb.PageController.index/2
  Parameters: %{}
  Pipelines: [:browser]
[info] Sent 500 in 26ms
[error] #PID<0.376.0> running LabWeb.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /
** (exit) an exception was raised:
    ** (Phoenix.Template.UndefinedError) Could not render "app.html" for LabWeb.LayoutView, please define a matching clause for render/2 or define a template at "lib/lab_web/templates/layout". No templates were compiled for this module.
Assigns:

%{conn: %Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{layout: {LabWeb.LayoutView, "app.html"}}, before_send: [#Function<0.59940076/1 in Plug.CSRFProtection.call/2>, #Function<4.124402890/1 in Phoenix.Controller.fetch_flash/2>, #Function<0.45862765/1 in Plug.Session.before_send/2>, #Function<1.34262281/1 in Plug.Logger.call/2>, #Function<0.832222/1 in Phoenix.LiveReloader.before_send_inject_reloader/2>], body_params: %{}, cookies: %{}, halted: false, host: "localhost", method: "GET", owner: #PID<0.376.0>, params: %{}, path_info: [], path_params: %{}, peer: {{127, 0, 0, 1}, 34494}, port: 4000, private: %{LabWeb.Router => {[], %{}}, :phoenix_action => :index, :phoenix_controller => LabWeb.PageController, :phoenix_endpoint => LabWeb.Endpoint, :phoenix_flash => %{}, :phoenix_format => "html", :phoenix_layout => {LabWeb.LayoutView, :app}, :phoenix_pipelines => [:browser], :phoenix_router => LabWeb.Router, :phoenix_template => "index.html", :phoenix_view => LabWeb.PageView, :plug_session => %{}, :plug_session_fetch => :done}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{}, req_headers: [{"host", "localhost:4000"}, {"connection", "keep-alive"}, {"cache-control", "max-age=0"}, {"upgrade-insecure-requests", "1"}, {"user-agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}, {"accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"}, {"referer", "http://localhost:4000/"}, {"accept-encoding", "gzip, deflate, br"}, {"accept-language", "en-US,en;q=0.9,es;q=0.8,fr;q=0.7"}], request_path: "/", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "a80k8c4jv29gepvqp03ebdtspiko5csk"}, {"x-frame-options", "SAMEORIGIN"}, {"x-xss-protection", "1; mode=block"}, {"x-content-type-options", "nosniff"}], scheme: :http, script_name: [], secret_key_base: "0VOVnDiOF2VZBh4+e9liE1QP/9a1YIHbLySbbctIX7//bpKKmIHjJ6MQ8jWRaFNm", state: :unset, status: nil}, template_not_found: LabWeb.LayoutView, view_module: LabWeb.PageView, view_template: "index.html"}

Assigned keys: [:conn, :template_not_found, :view_module, :view_template]

        (phoenix) lib/phoenix/template.ex:364: Phoenix.Template.raise_template_not_found/3
        (phoenix) lib/phoenix/view.ex:332: Phoenix.View.render_to_iodata/3
        (phoenix) lib/phoenix/controller.ex:740: Phoenix.Controller.do_render/4
        (lab) lib/lab_web/controllers/page_controller.ex:1: LabWeb.PageController.action/2
        (lab) lib/lab_web/controllers/page_controller.ex:1: LabWeb.PageController.phoenix_controller_pipeline/2
        (lab) lib/lab_web/endpoint.ex:1: LabWeb.Endpoint.instrument/4
        (phoenix) lib/phoenix/router.ex:278: Phoenix.Router.__call__/1
        (lab) lib/lab_web/endpoint.ex:1: LabWeb.Endpoint.plug_builder_call/2
        (lab) lib/plug/debugger.ex:99: LabWeb.Endpoint."call (overridable 3)"/2
        (lab) lib/lab_web/endpoint.ex:1: LabWeb.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) /home/david/dev/lab/lab/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

If I manually refresh the page, it renders with my added word in place.

I'm using

josevalim commented 6 years ago

@DavidVII sometimes people report issues once they enabled certain plugins in their editor, that try to automatically recompile the code. Then your editor ends-up racing with the Phoenix process. So I would start by stripping plugins or starting neovim in a "blank mode" and see if you can still reproduce it.

OvermindDL1 commented 6 years ago

I'm unsure about the vim extensions, but at least in emacs and atom I can configure what mix environment it should compile in (it compiles so it can get error messages and so forth for display), and I use test for that, which will not conflict with phoenix running in the default 'dev' mode anyway. :-)

DavidVII commented 6 years ago

@josevalim thanks for responding.

I had tried running neovim without an init file so there weren’t any plugins loaded. The problem unfortunately continued.

Perhaps this is an issue with the inotify-tools, but I’m not sure.

OvermindDL1 commented 6 years ago

As a side note, the thing that finally switched me from a lifelong vim/neovim user to emacs was the SpaceMacs plugin set for emacs, which has quite an interesting vim-like mode (evil mode when it asks upon first-time startup), and it works very well with elixir (set MIX_ENV=test before running emacs), maybe give it a try? :-)

josevalim commented 6 years ago

@DavidVII sorry for the delay, does the issue still exists? Does it happen if you use another editor?

DavidVII commented 6 years ago

@josevalim no problem at all.

Yes, this is still happening, but I think it may have something to do with neovim or possibly webpack. At some point, I was able to replicate this issue with a newly created phx app and neovim, but now I haven't been able to replicate it with a new app with just vim.

The issue does happen on an existing codebase that is running webpack. Not really sure what the deal is and honestly, I'm not sure I know where to look. I'm happy to test different things out if you have any ideas.

This does not happen in any other editor. I've only seen this happen in vim and neovim.

josevalim commented 6 years ago

@DavidVII if it only happens in neovim then it definitely feels like something is triggering the reload or messing up with file system, although I have no idea what it may be. I will leave it open in case somebody else has a clue or has the same issue. Thanks for the reply!

DavidVII commented 6 years ago

@josevalim it happens in regular vim as well. Also, it only happens on Ubuntu and not on MacOS. Feels like an odd issue and agree that it sounds like a file system thing. It's not a huge issue (for me at least) since a simple refresh gets me back on track, but it doesn't seem like others are experiencing this.

Cheers!