fix(states-editor): null-safe DOM ops so state merge survives missing COA/army elements#7
Merged
Merged
Conversation
… 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.
✅ Deploy Preview for bazgaars-fmg ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)returnsnull(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..select(...).attr("d")on an empty selection →getAttributeof null.armyN not found/provinceCOAN not foundconsole spam.Fix
Switch to
document.getElementById(...)?.remove()/ optional chaining (the safe-removal convention already used elsewhere). No behaviour change where the elements exist. Bumpedstates-editor.jscache-bust token?v=1.122.13→?v=1.122.14.Verified locally by inspection; functional verification in-browser by @barrulus.