From 490b337453100f397907c4e73ee23d15a5b56172 Mon Sep 17 00:00:00 2001 From: catborise Date: Tue, 6 Oct 2026 12:27:45 +0300 Subject: [PATCH] fix(instances): the VM page reloads only when the VM state changes The VM page polls the VM state every 5 s and reloads when it differs from the state the page was rendered with. Since the polling moved to pollWhileVisible, that state was kept in a top-level "var status", which is not a page variable but the browser's window.status. Where the browser does not keep a value there, the poll compared the answer with "" and reloaded the page every 5 s, back to its first tab. The variable is now vm_status. A Node test runs the page's script with a window.status that keeps nothing. --- instances/templates/instance.html | 5 +++-- webvirtcloud/test_poll_js.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 34c2aa4f..c5317690 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -652,11 +652,12 @@ ", source, re.S).group(1) + script = script.replace("{{ instance.status|lower }}", "1").replace( + "{% url 'instances:status' instance.id %}", "/instances/1/status/" + ) + js = """ + const vm = require("vm"); + const results = {}; + for (const answer of [1, 5]) { + let reloads = 0; + const page = { + pollWhileVisible: (interval, request, onData) => { onData({status: answer}); return {stop() {}}; }, + $: () => ({submit() {}}), + }; + page.window = {location: {reload: () => reloads++}}; + Object.defineProperty(page, "status", {get: () => "", set: () => {}}); + vm.runInNewContext(SCRIPT, vm.createContext(page)); + results[answer] = reloads; + } + console.log(JSON.stringify(results)); + """.replace("SCRIPT", json.dumps(script)) + out = subprocess.run(["node", "-e", js], capture_output=True, text=True, timeout=30) + self.assertEqual(out.returncode, 0, out.stderr) + self.assertEqual(json.loads(out.stdout), {"1": 0, "5": 1})