air icon indicating copy to clipboard operation
air copied to clipboard

Application is not being reload

Open sujit-baniya opened this issue 3 years ago • 16 comments

I'm trying to run app but on change it's not reloading

https://storyxpress.co/video/kld85zl4v0vjx5bls

I can't find the reason or place to debug.

sujit-baniya avatar Feb 20 '21 04:02 sujit-baniya

I have exactly the same problem, does not matter which file I change, It does not reload...

I have the full example that I am trying to implement here: https://github.com/kiketordera/advanced-performance

I do get air to work, but it does not do hot reload when I edit Golang files or HTML or CSS (I don't use the docker version of air, I want to deploy air with normal go code)

kiketordera avatar Feb 23 '21 21:02 kiketordera

@kiketordera I figured why app is not reloading.

Reason: we put a single folder in include field. That just ask air to watch files for that folder only. I see you're also using same

https://github.com/kiketordera/advanced-performance/blob/main/.air.conf#L21

Try to make it empty and it should work

sujit-baniya avatar Feb 23 '21 23:02 sujit-baniya

@sujit-baniya thank you very much for your feedback!

Unfortunately does not work. I tried with:

include_dir = []

I also tried with include_dir = ["/media/css", "media/css", "."]

and also one by one, nothing works for getting the hot reload to work. I am following the exact instructions that are written in the readme.md file to run it, I an not having any luck with it. I was able to develop a makefile for reloading Go code whenever Go code is changed, but my real goal is to reload the browser every time an HTML or CSS file changes.

kiketordera avatar Feb 24 '21 22:02 kiketordera

@kiketordera For me this is working fine:

.air.toml

# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Customize binary.
full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "css", "js", "env", "yaml"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "tmp", "vendor", "node_modules", "build"]
# Watch these directories if you specified.
include_dir = []
# Exclude files.
exclude_file = []
# Exclude unchanged files.
exclude_unchanged = true
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 1000 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true

sujit-baniya avatar Feb 25 '21 07:02 sujit-baniya

I think I did not express myself correctly, or maybe I am using the tool wrongly.

I want to reload the browser page whenever my code changes. Right now, whenever a file changes, it rebuilds the Golang code, which is nice, but it does not solve my problem of need to refresh manually the page in the browser to see the changes I apply to the files.

Thanks for your support!

kiketordera avatar Feb 28 '21 22:02 kiketordera

I want to reload the browser page whenever my code changes. Right now, whenever a file changes, it rebuilds the Golang code, which is nice, but it does not solve my problem of need to refresh manually the page in the browser to see the changes I apply to the files.

I don't think Air is the right tool for you then, as it's only job is to reload the Golang package.

HeCorr avatar Mar 06 '21 19:03 HeCorr

Go it thanks, can we then close this issue? So we maintain clean the repo

kiketordera avatar Mar 13 '21 11:03 kiketordera

@kiketordera maybe it's a nine-to-have feature:)

cosmtrek avatar Apr 23 '21 14:04 cosmtrek

@cosmtrek Does implementing a browser reload feature a breaking change? If not, perhaps the following repo can serve as a base for implementing the browser reload feature. I can try contributing if you are ok with it! https://github.com/qrtz/livedev

atreya2011 avatar Nov 28 '21 06:11 atreya2011

@cosmtrek Does implementing a browser reload feature a breaking change? If not, perhaps the following repo can serve as a base for implementing the browser reload feature. I can try contributing if you are ok with it! https://github.com/qrtz/livedev

it not breaking change. PR is welcome!

xiantang avatar Nov 28 '21 08:11 xiantang

it not breaking change. PR is welcome!

@xiantang Thank you 🙏🏼 Will start working on it 🙇🏼‍♂️

atreya2011 avatar Nov 28 '21 11:11 atreya2011

Thanks @atreya2011! When I read that this package is for "live-reload" of golang projects, I was excited and expected the browser to automatically refresh. Maybe I had a different understanding of the phrase, coming from a front-end developer perspective. Either way, rebuilding and restarting the server is a big help in-and-of-itself. With live-reload, it will be 🤌.

IanVS avatar Dec 20 '21 19:12 IanVS

Hey, I was thinking I would give implementing live browser reload a go (pun intended). I almost started creating my own tool for it but then realized implementing here might make more sense? Would y'all still be open to a PR for it? If so, would it be acceptable to utilize gorilla/websocket as a dependency for the WS implementation? @xiantang @cosmtrek any input would be appreciated. Thanks for the excellent tool 🙏

cwinters8 avatar Aug 20 '22 01:08 cwinters8

Any Updates on this issue ?

BennyDeeDev avatar Sep 06 '23 12:09 BennyDeeDev

The perfect solution 💕

Issue: Air is starting but not reloading on changes in the project

Solution: In .air.toml file add poll = true This is because Windows has some restrictions and to overcome that we set poll to true

Solution in code:

poll = true

swarajkumarsingh avatar Oct 07 '23 05:10 swarajkumarsingh

Hello, I've created a PR implementing live reloading in air. Any feedback is more than welcome, thanks!

ndajr avatar Jan 05 '24 08:01 ndajr