Exadra37

Exadra37

DISCLAIMER: I just play with Elixir and Phoenix occasionally.

In a default install of Phoenix we get this config:

config :tasks, TasksWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"priv/gettext/.*(po)$",
      ~r"lib/tasks_web/{live,views}/.*(ex)$",
      ~r"lib/tasks_web/templates/.*(eex)$"
    ]
  ]

The problem with the above config is that each time I edit a code file outside templates, views or live I need to manually restart the server, and this is so annoying and prone to forget, thus leading to debugging an error that doesn’t exist, aka I just forgot to restart the server… or am I missing something?

But this config works like a charm to me:

config :tasks, TasksWeb.Endpoint,
  live_reload: [
    patterns: [
      ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
      ~r"priv/gettext/.*(po)$",
      ~r"lib/tasks_web/.*(ex)$",
      ~r"lib/tasks/.*(ex)$",
    ]
  ]

So can I run in any weird situation because of using this type of live reload config?

Would not be better to have this live reload config by default?

Showing Posts 1 to 8

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

The live reload config you see here is about which files should, immediately on save, automatically trigger the page itself to reload.

It’s the code_reloader that handles recompiling your core Elixir code on page refresh. I ran a new copy of phoenix and saw the following in endpoint.ex:

  # Code reloading can be explicitly enabled under the
  # :code_reloader configuration of your endpoint.
  if code_reloading? do
    socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
    plug Phoenix.LiveReloader
    plug Phoenix.CodeReloader
  end

And when I checked dev.exs I see:

config :my_app_web, MyAppWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../apps/my_app_web/assets", __DIR__)
    ]
  ]

Importantly code_reloader: true. Does this line up with what you see in your project?

sb8244

sb8244

Author of Real-Time Phoenix

One potential issue here is what happens if you have a GenServer that assumes state in a certain format, then you change it, it reloads the code, and the old genserver state is now erroneous.

This is just speculation on my part, but I’m assuming that this is why the default is the way it is. The files that Phoenix owns are known to be safe, but your application cannot be known to be safe. Beginners may get even more confused by not knowing why things are broken.

Exadra37

Exadra37 OP

Code reloader is enabled:

config :tasks, TasksWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
  ]

Thanks for the explanation, but I see this issue across a lot of pet projects I play with, but I will try later in neu project and see if I can spot any difference.

Exadra37

Exadra37 OP

No using one, at least directly, plus this issue with code not reloading is across several projects.

This is what I am trying to understand, If the defaults are just playing on the safe side as you say or it’s something wrong in my setup.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Is there anything unusual about your development environment? Are you running stuff inside docker?

Exadra37

Exadra37 OP

Yes I am, and the container have inotify tools installed and the limit increased.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Which OS?

Exadra37

Exadra37 OP

OS

Host:

$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Container:

$ cat /etc/os-release                                                                                                                
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Inotify

Host

$ cat /etc/sysctl.conf | grep inotify - 
fs.inotify.max_user_watches=524288

Container

Seems this container is after all missing the increase in the inotify watchers… Seems that at some point in time I may have removed it accidentally from the base image.

I will fix this and see if it solves the issue.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews