Phoenix: Funky reload behavior with Atom

For some strange reason, when I switch tabs in Atom, or open a file in Atom, it’s causing Phoenix to re-compile assets and reload the page, even when there are no changes to those files.

For example:

click a .vue file tab in Atom:
17:19:37 - info: compiled myfile.vue and 320 cached files into app.js in 636 ms, and the page reloads.

click a .styl file tab in Atom:
17:20:27 - info: compiled myfile.styl and 4 cached files into app.css in 284 ms, and the page reloads.

This is happening without making any edits to those files. It’s not happening with .js files for some reason.

All I have to do is open the file in Atom, OR, click on one of the opened file’s tabs in Atom.

Can anyone who is using Atom confirm?

Me: MacOS, Atom version: 1.23.3

I’ve been using Atom and this was not happening before, so I’m not sure if an Atom update caused it, or if it’s anything that I’ve done. It’s certainly annoying!

Thanks in advance for any insight or suggestions.

p.s. This behavior is not happening in VS Code, so it does seem to be Atom related. I’m just not sure what the relationship between Atom/Phoenix could be to cause it, and I’m not sure where else to troubleshoot it.

1 Like

If you make a change to a file, but don’t save it, and then switch tabs, does it happen?

It kind of sounds like Atom is automatically saving/touching the file when you switch.

I’d definitely wouldn’t expect an editor to do that, though!

Thanks for the response, @tcollen.

It doesn’t happen if I make unsaved changes.

But as soon as I change focus to another tab, then switch focus back to that tab – live-reload recompiles and a new page refresh happens in the browser.

So it does seem like Atom is automatically touching or triggering a recompile when I focus the tab, but it’s not saving the file because otherwise I’d see those unsaved changes when the page reloads.

I just tried this all again in VS Code, opened files, switched tabs, etc., and I do not see any re-compiles.

Does this mean that this is some kind of a bug in Atom? Should I report it as such?

I hate to switch to using VS Code if I can help it (only because I’m comfortable and have all my plugins set up in Atom, so you know…change). But if I can’t get this figured out I may have to switch because I can’t work like this. :frowning:

Ok, it appears this is somehow related to Git.

If I change focus to the tab of a file that has unstaged changes, then I get the reload behavior (for any type of file, .vue, .js, .css, etc.).

If I change focus to the tab of a file without any changes, nothing happens (expected behavior).

If I then stage all the changes, reload continues indefinitely until I commit the changes (and this behavior is also happening in VS Code).

Anyone understand that relationship and why this might be happening? Why is Phoenix being triggered in that way?

Uh, I’ve not noticed it happening with atom here, what git plugins do you have, or rather what it your complete plugin list?

Thanks for your reply.

The git functionality is baked into Atom…not using anything special. I did try disabling ALL of my plugins (except for Atom core), restarted Atom, and still got the same behavior.

Here’s my plugin list, though:

atom-beautify@0.30.9
atom-elixir@0.2.3
atom-handlebars@1.3.0
atom-jshint@2.0.0
atom-live-server@2.2.0 (disabled)
atom-prettify@0.1.3
autocomplete-cfml@0.5.0
busy-signal@1.4.3
color-picker@2.2.5
elixir-cmd@0.2.9 (disabled)
emmet@2.4.3
ex-mode@0.18.0
file-icons@2.1.16
file-types@0.5.5
fonts@3.0.3
highlight-line@0.12.0
highlight-selected@0.13.1
html-to-elm@0.2.0 (disabled)
intentions@1.1.5
language-babel@2.83.1
language-cfml@0.17.1
language-elixir@0.20.3
language-elm@1.5.0 (disabled)
language-erlang@3.2.0
language-spacebars@0.2.2 (disabled)
language-vue@0.23.1
linter@2.2.0
linter-elm-make@0.28.1 (disabled)
linter-eslint@8.4.1
linter-ui-default@1.6.10
minimap@4.29.7
minimap-highlight-selected@4.6.1
minimap-pigments@0.2.2
multi-cursor@2.1.5
pigments@0.40.2
react@0.17.0 (disabled)
sync-settings@0.8.3
todo-show@2.1.0
vim-mode-plus@1.27.0
vim-surround@0.8.1 (disabled)```

If I stage the unstaged files, this happens indefinitely (using either command line, or Atom/VS Code):

14:13:38 - info: compiling
14:13:39 - info: Reloading watcher...
14:13:44 - info: compiling
14:13:45 - info: Reloading watcher...
14:13:49 - info: compiling
14:13:50 - info: Reloading watcher...
14:13:54 - info: compiling
14:13:55 - info: Reloading watcher...
14:14:00 - info: compiling
14:14:01 - info: Reloading watcher...
14:14:05 - info: compiling
14:14:07 - info: Reloading watcher...```

Hmm, wonder if it is something mac specific, I cannot replicate it on linux…

My suggestion would be to disable all plugins and see if the behaviour persists. If it doesn’t, add them back until you see the problem again.

Do you have any plugin that shows which lines are being added/removed from version control directly in the editor? That would be a good starting point.

2 Likes

Yeah, I have about everything they have and I don’t get the problem, so testing them via binary search might reveal what’s not working well on Mac’s. For note, grab the Atom Extension 'package-cop`, it allows you to bisect the extensions (it disables half, has you test, either swaps or repeats based on whether you said the issue happened or not, and keep repeating until you find the package with the issue).

Thanks, everyone. I appreciate the suggestions.

I’m continuing to hunt this down. :slight_smile:

Ok, so the Atom package, “status-bar” is related to the tab-focus recompiling of static assets.

However, there is still some relationship between Git (in general, not editor-related) and the watch/recompile process that I don’t understand. If I stage files (using ANY editor, OR command line git), it causes a perpetual, indefinite recompile until I stop the phoenix server or unstage the files.

Is there supposed to be a relationship between Git and the watch/recompile process in that way? Is that an expected behavior?

Also, if I re-enable the status-bar package, it only causes the recompile when I focus on the tab of a file with unstaged changes. For any other file, there is no recompile.

That’s, uh, weird… o.O
Did you find it out using package-cop? :slight_smile:

Well git doesn’t write to the file system except on very few calls… Maybe watch what PID’s are opening up on the files? Can always test with another filewatcher and see the specific events that are coming through too?

Hmm, I wonder if the reload is happening on ‘read’ requests too, not just write, that would be odd… Unless… does the Mac OS update the (access) timestamp of a file when it is read?

EDIT: Oh, I bet the status bar is showing git information yes?

1 Like

I didn’t find it with package-cop (although I did install that, so thanks for the recommendation).

So, it seems that Atom is the culprit after all, in all cases.

If I close Atom entirely, then staging files does not trigger the recompile when staging is initiated in any fashion. If Atom is open, and I use VS Code, or command line to stage, then recompile happens. Also, if I have Atom open and disable github package, then staging files does not trigger a recompile.

So, it appears to be something funky with github and status-bar packages in Atom. I still don’t necessarily understand it, but at least I know what’s causing it!

I was pulling my hair out thinking it might have been something in my recent code edits. I think I’ll spend some time with VS Code over the weekend to see if switching seems doable for me.

Next I’d definitely be running something like inotifywait (while atom is running) and have it print out every-single action it records happen to those files to see just what it looks like, then return that info here. :slight_smile:

:thinking: would fswatch work? I’ve never used anything like that before, so I’d be watching for changes in the same directories that brunch is watching, right? to see what change that brunch is reacting to?

Wait, is the reload behaviour happening on elixir source code or on javascript stuff?

the static asset stuff. .vue, .js, .css.

In that case what part is reloading repeatedly, is it brunch itself repeatedly re-running (or webpack or whatever you use), or is it the webpage constantly reloading/refreshing?

If I have a browser open, then it also refreshes the page that’s in the browser.

But otherwise, it’s recompiling with brunch.