Skip to content

Commit d337619

Browse files
committedJan 21, 2025
livereload: Close connection on pageshow
Fixes gohugoio#13287
1 parent 4b0c194 commit d337619

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed
 

‎livereload/gen/livereload-hugo-plugin.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,18 @@ HugoReload.prototype.reload = function (path, options) {
3131
return true;
3232
};
3333

34-
LiveReload.addPlugin(HugoReload);
34+
(function () {
35+
LiveReload.addPlugin(HugoReload);
36+
37+
// Close the WebSocket connection when the user leaves.
38+
window.addEventListener('pagehide', () => {
39+
console.log('Disconnecting LiveReload');
40+
LiveReload.connector.disconnect();
41+
});
42+
43+
// Open the connection when the page is loaded or restored from bfcache.
44+
window.addEventListener('pageshow', () => {
45+
console.log('Connecting LiveReload');
46+
LiveReload.connector.connect();
47+
});
48+
})();

‎livereload/livereload.min.js

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.