Skip to content

fix(states-editor): null-safe DOM ops so state merge survives missing COA/army elements#7

Merged
barrulus merged 1 commit into
mainfrom
fix/states-merge-null-safe-dom
Jun 9, 2026
Merged

fix(states-editor): null-safe DOM ops so state merge survives missing COA/army elements#7
barrulus merged 1 commit into
mainfrom
fix/states-merge-null-safe-dom

Conversation

@barrulus

@barrulus barrulus commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Follow-up to the states merge-to-provinces work. On the test map (Alvios), merging threw several errors and aborted partway.

Cause

All crashes are pre-existing base-merge bugs, not from the merge-to-provinces feature. This map's states have no rendered COA/army DOM nodes (some custom emblems fail to render). ensureEl(id) returns null (and logs) when an element is missing, so:

  • ensureEl("stateCOA"+id).remove()TypeError: Cannot read properties of null (reading 'remove')aborted the whole merge loop, leaving a half-merged pack.
  • hover highlight .select(...).attr("d") on an empty selection → getAttribute of null.
  • armyN not found / provinceCOAN not found console spam.

Fix

Switch to document.getElementById(...)?.remove() / optional chaining (the safe-removal convention already used elsewhere). No behaviour change where the elements exist. Bumped states-editor.js cache-bust token ?v=1.122.13?v=1.122.14.

Verified locally by inspection; functional verification in-browser by @barrulus.

… COA/army elements

The merge dialog crashed on maps whose states have no rendered COA/army DOM
nodes (e.g. custom emblems that failed to render). ensureEl() returns null +
logs when an element is missing, so ensureEl(id).remove()/.appendChild() threw:

- stateCOA removal (TypeError 'remove' of null) aborted the whole merge loop
  mid-iteration, leaving a half-merged pack — the user-visible breakage.
- hover highlight read .attr('d') on an empty selection (getAttribute of null).
- 'armyN not found' / 'provinceCOAN not found' console spam.

Switch these to document.getElementById(...)?.remove()/optional-chaining,
matching the safe-removal convention used elsewhere. No behaviour change on
maps where the elements exist. Bump states-editor cache-bust token to 1.122.14.

None of these lines were part of the merge-to-provinces feature; they are
pre-existing base-merge bugs surfaced by this map.
@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for bazgaars-fmg ready!

Name Link
🔨 Latest commit fd126a8
🔍 Latest deploy log https://app.netlify.com/projects/bazgaars-fmg/deploys/6a2880c1ff117b0008a9e4be
😎 Deploy Preview https://deploy-preview-7--bazgaars-fmg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@barrulus barrulus merged commit af93d99 into main Jun 9, 2026
6 checks passed
@barrulus barrulus deleted the fix/states-merge-null-safe-dom branch June 9, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant