phoenix_live_reload icon indicating copy to clipboard operation
phoenix_live_reload copied to clipboard

Live reload not triggering

Open mfeckie opened this issue 2 years ago • 2 comments
trafficstars

Version: {:phoenix_live_reload, "~> 1.2", only: :dev}

I have components in this folder lib/cockpit_web/components

with the following config for live_reload

  live_reload: [
    patterns: [
      ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"lib/cockpit_web/(components|live|views)/.*(ex)$",
      ~r"lib/cockpit_web/templates/.*(eex)$"
    ]
  ]

Saving files in the components folder, such as lib/cockpit_web/components/common.ex does not trigger a rebuild

Saving files in the live folder does. lib/cockpit_web/live/deployments_live.ex

I can't seem to figure out why this is the case and would love some insights into what I'm doing wrong

mfeckie avatar Feb 22 '23 07:02 mfeckie

Is it that the browser doesn't reload, or that saving doesn't trigger a rebuild?

I ran into an issue where saving would trigger a rebuild, but the browser wouldn't refresh until I manually reloaded the page, even for CSS changes in template files. If that's the issue you're seeing, make sure that your root.html.heex has a body html tag in it. I had moved the body tag to a different layout file, and that's when the browser refresh stopped working.

Based on this line it seems like the plug expects an HTML document with a body tag for it to work. @chrismccord is that true? Wonder if that's something that could be optionally configured?

Might be worth mentioning at least in the README, so noobs like me don't make that mistake 😂 Happy to open a PR if you think it's worth the effort!

ellismarkf avatar Mar 16 '23 02:03 ellismarkf

it seems like the plug expects an HTML document with a body tag for it to work

Excellent find, @ellismarkf . Thank you -- saved me some serious debugging.

I will add a specific issue to warn on this, since this one is broader.

wodow avatar Nov 01 '23 12:11 wodow

I ended up here for a different reason, but I found a solution. Adding it here just in case it helps someone else.

I use .devcontainer and develop inside that. The live reload wasn't working for me. I was pretty sure it had to do with how the file changes are handled from my PC to the container, or the choice of image I used, I'm not sure: FROM elixir:1.16.3-otp-26-slim

Putting this into my /config/config.esx solved the problem. Live reload works now.

config :phoenix_live_reload,
  backend: :fs_poll

I don't know how many people use containers for development environments. It might be good info for the README.

byte2pixel avatar Jul 29 '25 00:07 byte2pixel