block by eins78 6311abfbd62c47ab1b7318bd86e3b1dc

6311abfbd62c47ab1b73

NGB Tool: Manual Regions State-Loss Bugfix

2026-04-14T08:49:03Z by Showboat 0.6.1

Bugs Fixed

Branch: feature/LNTNGP24-568-manual-process Commits: b413c84, 2a3e006, 6ea3fe1

Bug 1: Text fields reset after ~5 seconds while editing

Root cause: ProcessSection was keyed on process.data.revisionId. The app polls server state every 5 seconds (UPDATE_INTERVAL). When the poll returned data after lock acquisition, the revisionId changed, causing ProcessSection to fully remount — destroying all in-progress text the user had typed.

Fix: Removed key={revisionId} from BulletinEditor.tsx. Added explicit syncedRevisionId state tracking in ProcessSection that resets state only on actual revision changes (React recommended “store previous props” pattern).

Bug 2: Toggling Pick/Manual destroyed the other modes data

Root cause: The radio toggle handler called setEdited(...) to eagerly strip the inactive modes data. Additionally, updateProcessEntry stripped the other modes data whenever regions or manualRegions were updated.

Fix: Removed all eager stripping. Both regions and manualRegions coexist in edit state. Mode consolidation is deferred to buildPayload(table, isManual) at save time.

Bug 3: Discard did not reset manual regions toggle

Root cause: handleDiscardChanges reset edited state but not manualRegions.

Fix: Added setManualRegions(hasManualRegions(initialContent)) to discard handler.

Bug 4: Stale RegionDefiner ref after save-with-lock

Root cause: RegionDefiner uses useRef to accumulate text across fields. After save or discard, the parent resets edited state but the refs internal value was stale (from before the save).

Fix: Added key={syncedRevisionId} to RegionDefiner so it remounts when the revision changes.

npx tsc --noEmit -p tsconfig.app.json && echo "TypeScript: OK"
TypeScript: OK
npx jest --testPathPattern "Process|Region" 2>&1 | tail -8
PASS src/components/bulletin-editor/RegionDefiner.spec.tsx
PASS src/components/bulletin-editor/RegionPicker.spec.tsx

Test Suites: 5 passed, 5 total
Tests:       34 passed, 34 total
Snapshots:   1 passed, 1 total
Ran all test suites matching /Process|Region/i.
git log --oneline HEAD~4..HEAD
6ea3fe197 b Fix stale state after discard and save-with-lock
2a3e006c4 r Simplify ProcessSection: extract hasManualRegions, derive language default
b413c8421 b Fix manual regions state loss on mode toggle and background poll
05ce62a75 r Simplify RegionDefiner: use onChange prop instead of native event listeners

Browser Verification

Toggle round-trip: Manual -> Pick -> Manual

Before fix: Switching from Manual to Pick destroyed manualRegions data. Switching back showed empty fields.

After fix: All data preserved across toggles. Consolidation happens only at save time.

Step 1: Avalanche section open in edit mode, Pick selected with “Appenzell Innerrhoden”

Fresh state

Step 2: Toggled to Manual, entered text in all 3 languages

Manual with text

Step 3: Toggled back to Pick — region “Appenzell Innerrhoden” still there

Toggled to Pick

Step 4: Toggled back to Manual — all 3 language texts preserved

Back to Manual preserved

2026-04-14-manual-regions-bugfix.md