Browser preview does not auto-reload

I am using "Preview in browser" feature in PHPStorm. Preview works, but auto-reload described here does not.

I am using a static website generator (staticjinja), which is watching for changes in templates and compiles to a `dist` folder. The browser preview is opened from a compiled dist folder. From the above mentioned docs I would expect that browser would reload automatically, since the compiled file was changed (by the watcher). However, that's not the case. Any idea?

"Tools > Web browsers and preview > Reload behavior > Reload page in browser" is set to "On change".

1
7 comments

Hi there,

Does the preview works OK after you use "File | Reload All from Disk"?

 

If I'm getting this correctly, staticjinja watches for the changes (and does the compilation) in the background. But the IDE does not check for external file modifications all the time. It does that only when getting the focus back from another app or on the aforementioned Reload action. Since the Preview is based on what the IDE knows about the file, it simply does not see such external modification... but it would work if you modify that compiled file in the IDE. That's my best explanation for this.

0

Does the preview works OK after you use "File | Reload All from Disk"?

I had this thought too, but no, it has no effect, I tried. I also tried previewing in built-in PS browser, same result.

It does not reload even when I modify the compiled file directly.

0

Maybe your dist folder is marked as excluded of some kind (e.g. treated as generated content etc)? I'm not sure at all (as I do not use this feature), but I have seen some notes in the past that suggest that a folder with such a name might be auto excluded...

Other than that: this is the best possibly-related ticket that I have found in WEB project: https://youtrack.jetbrains.com/issue/WEB-52246/Reload-on-save-doesnt-work-for-files-outside-of-a-project-root

An actual JetBrains Support Team member should have a better insight.

0

Ok, after trying it on a fresh project, I have two updates.

The reload feature indeed works as intended, but – what is not mentioned anywhere, is that the feature relies on _ij_reload=RELOAD_ON_CHANGE variable being present in the query string in the browser. That is only appended automatically, if you do not set "Web server URL" in your deployment configuration. That's the one reason it did not work on existing project, but worked well on a new one – I just already had some deployment configuration.

The second problem is exactly what you mentioned before – after fixing the query variable, you need to manually use "File | Reload All from Disk" to trigger the reload.

But then comes my next question: what's the difference between reloading "On save" and "On change"? I thought its purpose was exactly to differentiate the situations, when you only directly editing the file, and when the file get's modified by any other possible means?

0

But then comes my next question: what's the difference between reloading "On save" and "On change"? I thought its purpose was exactly to differentiate the situations, when you only directly editing the file, and when the file get's modified by any other possible means?

See https://www.jetbrains.com/help/phpstorm/settings-tools-web-browsers.html#ws_configure_browsers_reload_behavior

  • On Save -- the reload happens on file save.
  • On Change -- happens as you type (in that file)
0

The second problem is exactly what you mentioned before – after fixing the query variable, you need to manually use "File | Reload All from Disk" to trigger the reload.

So it works, right?

If so -- can you run your staticjinja (the compilation process) not in the background ... but inside the IDE when needed (as a File Watcher tool)? You may then specify the path to check for external modifications and point to the specific file(s) that you are interested in at this moment... At very least try it.

0

So it works, right?

Yes, the feature itself is working as it should.

Thanks for the "File Watcher" tip, I finally got it working as desired! Although there is one caveat – for the File Watcher, you need to configure your tool for the build step, not for the watch.

Also, I must mention, that I was already running staticjinja inside the IDE – as a Run Configuration – not in the background... Apparently, the "Output paths to refresh" is the dealbreaker, Run Configurations do not have that.

0

Please sign in to leave a comment.