Commit a12309c
fix: handle undefined projection in setProjection to prevent setState crash (maplibre#7330)
* test: add failing test for setState crash when target style has no projection
setState crashes with "Cannot read properties of undefined (reading 'type')"
when switching from a style with an explicit projection to one without.
The diff() function emits {command: 'setProjection', args: [undefined]},
and setProjection(undefined) dereferences undefined.type.
* fix: skip setProjection in setState style diff
Projection is owned by the map, not the style. setState should not mutate
it as a side effect of diffing two style JSONs. This matches the existing
pattern for setCenter/setZoom/setBearing/setPitch/setRoll, which are also
skipped during style diffs.
* test: update 'do operations if there are changes' test to remove the setProjection spy
and projection assignment, since setState no longer processes projection
diff commands.
* chore: add changelog entry for maplibre#7314
* fix: handle undefined projection in setProjection
When setState diffs a style with a projection field against one without,
diff() emits setProjection(undefined) which crashes on undefined.type.
Default to {type: 'mercator'} when projection is undefined, so
setProjection handles a missing value without crashing.
* fix: preserve original projection value in stylesheet during setProjection
* Apply suggestion from @HarelM
---------
Co-authored-by: Harel M <harel.mazor@gmail.com>1 parent ebee9f7 commit a12309c
3 files changed
Lines changed: 31 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
1106 | 1133 | | |
1107 | 1134 | | |
1108 | 1135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1685 | 1685 | | |
1686 | 1686 | | |
1687 | 1687 | | |
| 1688 | + | |
1688 | 1689 | | |
1689 | 1690 | | |
1690 | | - | |
| 1691 | + | |
1691 | 1692 | | |
1692 | 1693 | | |
1693 | 1694 | | |
1694 | 1695 | | |
1695 | 1696 | | |
1696 | | - | |
| 1697 | + | |
1697 | 1698 | | |
1698 | 1699 | | |
1699 | 1700 | | |
| |||
0 commit comments