fix: guard against page-navigation race + deprecation warning
- playerInfo refresh() now early-returns if DOM elements are gone (happens when navigating away while getPlayers RCON is in flight) - swiched donutLabelsOutside(false) → labelsOutside(false) to silence NVD3 deprecation warning Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+14
-7
@@ -40,19 +40,25 @@ function PlayerInfoPage(params, container) {
|
|||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
Rcon.getPlayers(function (players) {
|
Rcon.getPlayers(function (players) {
|
||||||
|
// Guard against navigation away while waiting for RCON response
|
||||||
|
var nf = document.getElementById('pi-notfound');
|
||||||
|
var fields = document.getElementById('pi-fields');
|
||||||
|
var actions = document.getElementById('pi-actions');
|
||||||
|
if (!nf || !fields || !actions) return;
|
||||||
|
|
||||||
var info = null;
|
var info = null;
|
||||||
for (var i = 0; i < players.length; i++) {
|
for (var i = 0; i < players.length; i++) {
|
||||||
if (String(players[i].SteamID) === userid) { info = players[i]; break; }
|
if (String(players[i].SteamID) === userid) { info = players[i]; break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
document.getElementById('pi-notfound').style.display = 'block';
|
nf.style.display = 'block';
|
||||||
document.getElementById('pi-fields').innerHTML = '';
|
fields.innerHTML = '';
|
||||||
document.getElementById('pi-actions').style.display = 'none';
|
actions.style.display = 'none';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
document.getElementById('pi-notfound').style.display = 'none';
|
nf.style.display = 'none';
|
||||||
document.getElementById('pi-actions').style.display = 'block';
|
actions.style.display = 'block';
|
||||||
|
|
||||||
// Fix known Rust RCON quirk: VoiationLevel → ViolationLevel
|
// Fix known Rust RCON quirk: VoiationLevel → ViolationLevel
|
||||||
if (info.VoiationLevel !== undefined) {
|
if (info.VoiationLevel !== undefined) {
|
||||||
@@ -64,7 +70,8 @@ function PlayerInfoPage(params, container) {
|
|||||||
delete info.CurrentLevel;
|
delete info.CurrentLevel;
|
||||||
delete info.UnspentXp;
|
delete info.UnspentXp;
|
||||||
|
|
||||||
document.getElementById('pi-username').textContent = info.DisplayName || userid;
|
var un = document.getElementById('pi-username');
|
||||||
|
if (un) un.textContent = info.DisplayName || userid;
|
||||||
|
|
||||||
var fieldsHtml = '';
|
var fieldsHtml = '';
|
||||||
for (var key in info) {
|
for (var key in info) {
|
||||||
@@ -79,7 +86,7 @@ function PlayerInfoPage(params, container) {
|
|||||||
fieldsHtml += '<div class="col-sm-4"><p>' + key + ': <span class="badge">' + value + '</span></p></div>';
|
fieldsHtml += '<div class="col-sm-4"><p>' + key + ': <span class="badge">' + value + '</span></p></div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
document.getElementById('pi-fields').innerHTML = fieldsHtml;
|
fields.innerHTML = fieldsHtml;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ function ServerInfoPage(params, container) {
|
|||||||
.y(function (d) { return d.y; })
|
.y(function (d) { return d.y; })
|
||||||
.showLabels(true)
|
.showLabels(true)
|
||||||
.donut(true)
|
.donut(true)
|
||||||
.donutLabelsOutside(false)
|
.labelsOutside(false)
|
||||||
.duration(500)
|
.duration(500)
|
||||||
.height(250)
|
.height(250)
|
||||||
.color(['#a78bfa', '#7c3aed', '#e879f9', '#2d1f3d'])
|
.color(['#a78bfa', '#7c3aed', '#e879f9', '#2d1f3d'])
|
||||||
|
|||||||
Reference in New Issue
Block a user