mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-11-22 12:07:15 +00:00
fix(repeater-info): keep an open edit form on screen through a re-render (#2437)
## What On the full node page, an open repeater-info edit form now stays on screen when the page re-renders (`theme-refresh`). Before, the fresh section stayed empty until `GET /api/repeaters/<pk>/info` answered. ## Why `loadFullNode` (`public/nodes.js`) replaces the page body and calls `CSRepeaterInfo.mount` on a fresh element. `mount` kept the typed values in its `drafts` map, but only showed the form again after the GET, so for one round trip the form was gone. That made `tests/e2e/test-user-management-e2e.js` flaky. Every page load fires one `theme-refresh` about 300 ms after `/api/config/theme` resolves. On CI that refresh sometimes landed between filling the form and the `page.evaluate` that marks the notes field, which then threw `Cannot read properties of null (reading 'dataset')`. The three later repeater-info steps failed as a consequence. Since 2026-11-10 this happened in 2 of about 150 CI runs: run 44506140120 (#2435) and run 44187421862 (a docs-only branch). Reproduced locally with `/info` delayed 600 ms and a `theme-refresh` after filling the form: the notes field was missing during the refresh on the old code, and present on this branch (3 of 3 runs). ## Changes `public/repeater-info.js`: - `mount` shows an open draft at once, in the same task as the re-render. The GET only replaces it when the user lost edit rights. - Cancel before the GET answers no longer throws on a null `info`; the section stays hidden until the view can render. - A failed GET leaves an open form in place. - A save on the early form is not overwritten by the older GET answer. - A section the page already replaced ignores its late GET, so it cannot delete the draft its successor owns. `tests/e2e/test-user-management-e2e.js:745`: the side-pane step collapsed whitespace with `/s+/`; now `/\s+/`. ## Tests - `tests/unit/test-repeater-info.js`: 6 new cases, 27 pass. All 6 fail on the old `repeater-info.js`. - `tests/e2e/test-user-management-e2e.js`: 44/44 locally against an `e2etest` build, run twice. - `test-all.sh`: green locally, except the three suites that also fail on master on Windows (`test-manage-workflow.js`, `test-preflight-xss-gate.js`, `test-dev-static.js`). ## Not done - The side pane (`#node-repeater-info-pane`) still has a short gap. On `theme-refresh`, `selectNode` shows "Loading…" before `fetchNodeDetail` and only then mounts. The draft comes back, but the form is off screen during that fetch. Fixing it means changing the pane render path in `nodes.js`, which is outside this PR. - Focus and caret are still lost when the form is rebuilt. That was already the case before this PR.
This commit is contained in:
1 parent
87b70562fd
commit
ca74bc12f9
3 files changed
+102
-5
No files matched your search
+14
-4
@@ -135,9 +135,14 @@
|
||||
var form = el.querySelector('[data-ri-form]');
|
||||
if (form) drafts[slot] = { pk: pk, values: rawForm(form) };
|
||||
}
|
||||
// shown is the mode on screen, or '' while nothing is (the view before
|
||||
// the GET answered).
|
||||
var shown = '';
|
||||
function show(mode, values) {
|
||||
var user = auth.user();
|
||||
if (mode !== 'edit') delete drafts[slot];
|
||||
if (mode === 'view' && !info) { shown = ''; el.innerHTML = ''; el.hidden = true; return; }
|
||||
shown = mode;
|
||||
el.innerHTML = '<h4>Repeater info</h4>' +
|
||||
(mode === 'edit' ? formHtml(values || info) : mode === 'confirm' ? confirmHtml() : viewHtml(info, user));
|
||||
if (mode === 'edit' && !values) keep();
|
||||
@@ -182,12 +187,17 @@
|
||||
return Promise.resolve(auth.ready()).then(function () {
|
||||
if (!auth.isEnabled()) return;
|
||||
bind();
|
||||
// An open draft comes back at once, in the same task as the re-render:
|
||||
// waiting for the GET would empty the section for a round trip.
|
||||
var d = drafts[slot];
|
||||
if (d && d.pk === pk) { show('edit', d.values); el.hidden = false; }
|
||||
return auth.request('GET', base + '/info').then(function (r) {
|
||||
if (!r.ok) return;
|
||||
// A section the node page already replaced must not touch the draft
|
||||
// its successor owns.
|
||||
if (!r.ok || el.isConnected === false) return;
|
||||
if (info) return; // a save on the early form already brought newer data
|
||||
info = r.data;
|
||||
var d = drafts[slot];
|
||||
if (d && d.pk === pk && info.canEdit) show('edit', d.values);
|
||||
else show('view');
|
||||
if (shown !== 'edit' || !info.canEdit) show('view');
|
||||
el.hidden = false;
|
||||
var hash = String(window.location.hash || '');
|
||||
if (hash.indexOf('section=node-repeater-info') !== -1 && el.scrollIntoView) el.scrollIntoView();
|
||||
|
||||
@@ -742,7 +742,7 @@ async function until(fn, label) {
|
||||
await userA.click(row);
|
||||
const pane = '#node-repeater-info-pane';
|
||||
await userA.waitForSelector(pane + ':not([hidden]) .repeater-info-list');
|
||||
const t = (await userA.innerText(pane)).replace(/s+/g, ' ');
|
||||
const t = (await userA.innerText(pane)).replace(/\s+/g, ' ');
|
||||
assert(t.indexOf('25 m') !== -1, 'pane height missing: ' + t);
|
||||
});
|
||||
|
||||
|
||||
@@ -264,6 +264,93 @@ test('no draft after Cancel, a save, a hashchange, another repeater or lost edit
|
||||
l.auth.request = () => Promise.resolve({ ok: true, status: 200, data: INFO({ canEdit: false }) });
|
||||
assert(!(await remountShowsForm(l)), 'draft shown without edit rights');
|
||||
});
|
||||
// A re-mount with an open draft shows the form at once: waiting for the GET
|
||||
// left the section empty for a round trip, the form vanished from under the
|
||||
// user and the E2E read a missing notes field.
|
||||
function remountWithPendingGet() {
|
||||
const opts = { info: INFO({ canEdit: true }), form: { heightM: '25', gainDbi: '0', status: '', power: '', notes: 'typed' } };
|
||||
const l = load(opts);
|
||||
const a = mountFlow(opts, l);
|
||||
return l.R.mount(a.el, { public_key: PK, role: 'repeater' }).then(() => {
|
||||
a.click('data-ri-edit');
|
||||
a.el.handlers.input({});
|
||||
const pend = [];
|
||||
l.auth.request = (method) => new Promise((ok, fail) => { pend.push({ method, ok, fail }); });
|
||||
const b = mountFlow(opts, l);
|
||||
const done = l.R.mount(b.el, { public_key: PK, role: 'repeater' });
|
||||
return tick().then(() => ({ b, done, pend, answer: (res) => { pend[0].ok(res); return done; } }));
|
||||
});
|
||||
}
|
||||
test('a re-mount shows the draft form before the GET answers', async () => {
|
||||
const { b, answer } = await remountWithPendingGet();
|
||||
assert(b.el.innerHTML.includes('data-ri-form') && b.el.innerHTML.includes('typed'), 'no form while the GET is out: ' + b.el.innerHTML);
|
||||
assert.strictEqual(b.el.hidden, false);
|
||||
b.el.innerHTML += '<!--user state-->';
|
||||
await answer({ ok: true, status: 200, data: INFO({ canEdit: true }) });
|
||||
assert(b.el.innerHTML.includes('<!--user state-->'), 'the GET re-rendered the open form');
|
||||
});
|
||||
test('the early draft form gives way to the view when the GET says no edit rights', async () => {
|
||||
const { b, answer } = await remountWithPendingGet();
|
||||
await answer({ ok: true, status: 200, data: INFO({ canEdit: false }) });
|
||||
assert(!b.el.innerHTML.includes('data-ri-form'), b.el.innerHTML);
|
||||
assert(b.el.innerHTML.includes('No details yet.'), b.el.innerHTML);
|
||||
});
|
||||
test('Cancel on the early draft form before the GET answers, then the view', async () => {
|
||||
const { b, answer } = await remountWithPendingGet();
|
||||
b.click('data-ri-cancel');
|
||||
assert(!b.el.innerHTML.includes('data-ri-form'), b.el.innerHTML);
|
||||
await answer({ ok: true, status: 200, data: INFO({ canEdit: true, heightM: 9, updatedAt: 'x' }) });
|
||||
assert(b.el.innerHTML.includes('9 m'), b.el.innerHTML);
|
||||
});
|
||||
test('a failed GET hides the section unless the draft form is open', async () => {
|
||||
let r = await remountWithPendingGet();
|
||||
await r.answer({ ok: false, status: 500, data: {} });
|
||||
assert(r.b.el.innerHTML.includes('data-ri-form') && r.b.el.hidden === false, 'open form dropped on a failed GET');
|
||||
r = await remountWithPendingGet();
|
||||
r.b.click('data-ri-cancel');
|
||||
await r.answer({ ok: false, status: 500, data: {} });
|
||||
assert.strictEqual(r.b.el.hidden, true);
|
||||
});
|
||||
test('a save on the early form is not overwritten by the older GET answer', async () => {
|
||||
const { b, pend, answer } = await remountWithPendingGet();
|
||||
b.click('data-ri-save');
|
||||
assert.strictEqual(pend[1].method, 'PUT');
|
||||
pend[1].ok({ ok: true, status: 200, data: INFO({ canEdit: true, heightM: 30, updatedAt: 'x' }) });
|
||||
await tick();
|
||||
await answer({ ok: true, status: 200, data: INFO({ canEdit: true, heightM: 5, updatedAt: 'x' }) });
|
||||
assert(b.el.innerHTML.includes('30 m') && !b.el.innerHTML.includes('5 m'), b.el.innerHTML);
|
||||
});
|
||||
test('a network error on the GET hides the section unless the draft form is open', async () => {
|
||||
let r = await remountWithPendingGet();
|
||||
r.pend[0].fail(new Error('net'));
|
||||
await r.done;
|
||||
assert(r.b.el.innerHTML.includes('data-ri-form') && r.b.el.hidden === false, 'open form dropped on a network error');
|
||||
r = await remountWithPendingGet();
|
||||
r.b.click('data-ri-cancel');
|
||||
r.pend[0].fail(new Error('net'));
|
||||
await r.done;
|
||||
assert.strictEqual(r.b.el.hidden, true);
|
||||
});
|
||||
test('a late GET of a replaced section leaves the draft of its successor alone', async () => {
|
||||
const opts = { info: INFO({ canEdit: true }), form: { heightM: '25', gainDbi: '0', status: '', power: '', notes: 'typed' } };
|
||||
const l = load(opts);
|
||||
let answerA;
|
||||
l.auth.request = () => new Promise((r) => { answerA = r; });
|
||||
const a = mountFlow(opts, l);
|
||||
const doneA = l.R.mount(a.el, { public_key: PK, role: 'repeater' });
|
||||
await tick();
|
||||
a.el.isConnected = false;
|
||||
l.auth.request = () => Promise.resolve({ ok: true, status: 200, data: INFO({ canEdit: true }) });
|
||||
const b = mountFlow(opts, l);
|
||||
await l.R.mount(b.el, { public_key: PK, role: 'repeater' });
|
||||
b.click('data-ri-edit');
|
||||
b.el.handlers.input({});
|
||||
answerA({ ok: true, status: 200, data: INFO({ canEdit: true }) });
|
||||
await doneA;
|
||||
const c = mountFlow(opts, l);
|
||||
await l.R.mount(c.el, { public_key: PK, role: 'repeater' });
|
||||
assert(c.el.innerHTML.includes('data-ri-form'), 'the stale GET dropped the draft: ' + c.el.innerHTML);
|
||||
});
|
||||
test('anonymous visitor sees one login hint, a logged-in user does not', () => {
|
||||
const anon = load({ user: null }).R._test.viewHtml(INFO(), null);
|
||||
assert(anon.includes('Log in to claim or edit this repeater.'));
|
||||
|
||||
Reference in new issue
Block a user