test: deflake map fill gate and wall-locked under load
Map gate (a): measure the fastest of 4 fresh page loads after a warm-up (min-of-N, TESTING 5.3) against 2x the 1 s DESIGN budget (the documented saturated-host tolerance), and print every sample; a planted 50 ms/tile decode delay fails it. Wall editor: an ack dispatch re-renders with the previous server record, and the panel repopulated every control on every render, so a just-toggled checkbox was reverted until the wall frame landed (Playwright saw 'did not change its state'). Repopulate only when the record changed (src/panels/wallSync.ts, unit-tested) and restore the controls when the server refuses an edit.
This commit is contained in:
+21
-10
@@ -17,6 +17,8 @@ import { sendIntent } from '../intents.ts'
|
||||
import type { WallView } from '../slices/walls.ts'
|
||||
import { restoreOf, selectedWallOf, undoOf, wallsOf } from '../slices/walls.ts'
|
||||
import type { SightDir, WallPreset, WallSwitches, WallUndo } from '../wallEditor.ts'
|
||||
import type { PopulatedWall } from './wallSync.ts'
|
||||
import { shouldPopulate, wallFieldsSignature } from './wallSync.ts'
|
||||
import {
|
||||
PRESETS,
|
||||
buildAddFields,
|
||||
@@ -225,7 +227,8 @@ export function mountWallPanel(
|
||||
let armed = false
|
||||
let first: Vec2 | null = null
|
||||
let snapEnabled = true
|
||||
let populatedFor = -1
|
||||
/** The server record last copied into the controls (id + field signature), or null. */
|
||||
let populated: PopulatedWall | null = null
|
||||
let advancedOpen = false
|
||||
/** The last rendered wall record, so a field edit uses exactly what the GM saw. */
|
||||
let shown: WallView | null = null
|
||||
@@ -371,7 +374,7 @@ export function mountWallPanel(
|
||||
// Clearing `door` is the one patch that also closes/de-secrets server-side (6.1), so it is sent
|
||||
// alone rather than as a contradictory full switch set.
|
||||
if (key === 'door' && value === false) {
|
||||
await patch({ door: false }, prior)
|
||||
if (!(await patch({ door: false }, prior))) populate(prior)
|
||||
return
|
||||
}
|
||||
const merged = mergedSwitches({ [key]: value } as Partial<WallSwitches>)
|
||||
@@ -396,6 +399,9 @@ export function mountWallPanel(
|
||||
flags: { ...prior.flags },
|
||||
},
|
||||
})
|
||||
} else {
|
||||
// The server refused: put the control back to the record the GM last saw.
|
||||
populate(prior)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,7 +591,7 @@ export function mountWallPanel(
|
||||
armed = false
|
||||
first = null
|
||||
shown = null
|
||||
populatedFor = -1
|
||||
populated = null
|
||||
root.hidden = true
|
||||
selected.hidden = true
|
||||
setError(null)
|
||||
@@ -596,7 +602,7 @@ export function mountWallPanel(
|
||||
}
|
||||
if (!active) {
|
||||
active = true
|
||||
populatedFor = -1
|
||||
populated = null
|
||||
}
|
||||
root.hidden = false
|
||||
|
||||
@@ -604,15 +610,15 @@ export function mountWallPanel(
|
||||
shown = wall
|
||||
if (wall === null) {
|
||||
selected.hidden = true
|
||||
populatedFor = -1
|
||||
populated = null
|
||||
undoButton.textContent = undoLabel(undoOf(state))
|
||||
undoButton.disabled = undoOf(state) === null
|
||||
return
|
||||
}
|
||||
selected.hidden = false
|
||||
selectedTitle.textContent = `${wall.kind}`
|
||||
if (populatedFor !== wall.id) {
|
||||
populatedFor = wall.id
|
||||
if (populated?.id !== wall.id) {
|
||||
populated = null
|
||||
advancedOpen = false
|
||||
advanced.hidden = true
|
||||
advancedToggle.setAttribute('aria-expanded', 'false')
|
||||
@@ -620,9 +626,14 @@ export function mountWallPanel(
|
||||
unlockButton.hidden = true
|
||||
setError(null)
|
||||
}
|
||||
// Do not overwrite a field the GM is typing in; the server's record still drives every other
|
||||
// control and the derived kind.
|
||||
if (document.activeElement !== labelInput.node) populate(wall)
|
||||
// Repopulate only when the server record changed: an ack dispatch carries the previous record
|
||||
// and must not undo the switch the GM just made while the authoritative frame is in flight.
|
||||
// Do not overwrite a field the GM is typing in either; the server's record still drives every
|
||||
// other control and the derived kind.
|
||||
if (shouldPopulate(populated, wall) && document.activeElement !== labelInput.node) {
|
||||
populate(wall)
|
||||
populated = { id: wall.id, signature: wallFieldsSignature(wall) }
|
||||
}
|
||||
kindHint.textContent = `Derived kind: ${wall.kind}`
|
||||
openButton.textContent = wall.switches.open ? 'Close door' : 'Open door'
|
||||
openButton.disabled = !wall.switches.door
|
||||
|
||||
Reference in New Issue
Block a user