DEFAULT_SETTINGS.maxBounds in @vis.gl/react-maplibre has 360° longitude span, triggers maplibre-gl-js#6148 crash via _updateSettings fallback
还没有人认领这个 Issue。
- #2617 来自 @cpruijsen —— 已关闭,未合并
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 74/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- react, typescript
调研方向
从 maplibre/maplibre.ts 开始,阅读 DEFAULT_SETTINGS 和 _updateSettings,以了解 maxBounds 的非对称回退。根据报告的 context-loss 复现情况验证此更改,并确认省略 maxBounds 后不再发送 360° 的经度范围,也不再触发 maplibre 崩溃。
由索引模型根据 Issue 内容生成。
描述
Filing here since
visgl/react-maplibreis archived and points back to this monorepo. Bug is in the published@vis.gl/[email protected](also reached via[email protected]'s/maplibreentry).
Summary
DEFAULT_SETTINGS.maxBounds is hard-coded to [-180, -85.051129, 180, 85.051129], which has a longitude span of exactly 360°. When _updateSettings falls back to this default (when the maxBounds key is present in only one of nextProps / currProps), it calls map.setMaxBounds([-180, -85.051129, 180, 85.051129]) on the underlying maplibre instance. Because the longitude bounds span the full world, the upstream bug maplibre/maplibre-gl-js#6148 fires: the projection matrix becomes singular and non-invertible, throwing:
TypeError: Cannot read properties of null (reading '0')
(Firefox:can't access property 0, i is null)
Stack
Ge maplibre-gl-...js
_calcMatrices
calcMatrices
_calcMatrices
setZoom
constrainInternal
setMaxBounds // TransformHelper
setMaxBounds // MercatorTransformImpl
setMaxBounds // Map (maplibre)
_updateSettings // @vis.gl/react-maplibre
Code reference
In the published @vis.gl/[email protected] (dist/index.cjs lines 220-228, equivalent in source maplibre/maplibre.ts):
const DEFAULT_SETTINGS = {
minZoom: 0,
maxZoom: 22,
minPitch: 0,
maxPitch: 85,
maxBounds: [-180, -85.051129, 180, 85.051129], // <-- 360° longitude span
projection: 'mercator',
renderWorldCopies: true,
};
And the fallback in _updateSettings (dist/index.cjs lines 517-529):
_updateSettings(nextProps, currProps) {
const map = this._map;
let changed = false;
for (const propName of settingNames) {
const propPresent = propName in nextProps || propName in currProps;
if (propPresent && !deepEqual(nextProps[propName], currProps[propName])) {
changed = true;
const nextValue = propName in nextProps
? nextProps[propName]
: DEFAULT_SETTINGS[propName];
// ^ when 'maxBounds' is in currProps but not nextProps, this picks
// the 360°-span world bounds, which maplibre then chokes on.
const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
setter?.call(map, nextValue);
}
}
return changed;
}
How we hit it in production
Consumer code never passes maxBounds to <Map>. But:
- Firefox aggressively drops WebGL contexts when the tab is backgrounded.
- On tab return, maplibre's internal
_contextLostnullsthis.style, leaving the transform in a partial state. - A subsequent React render causes
setProps → _updateSettings. Under some prop-shape change (e.g.viewState/mapStyle/mapPropsreshape), themaxBoundskey in the previous-vs-current props comparison hits the asymmetric branch where it falls back toDEFAULT_SETTINGS.maxBounds. setMaxBounds([-180, -85.05, 180, 85.05])runs against the partially-restored transform → maplibre tries to invert a singular matrix → null deref.
Reproduces on both Firefox and Chrome. We verified by forcing context loss with WEBGL_lose_context.loseContext() followed by restoreContext() — Chrome hits the same crash, just less spontaneously than Firefox.
Suggested fix
Change DEFAULT_SETTINGS.maxBounds from the 360° world bounds to null:
const DEFAULT_SETTINGS = {
minZoom: 0,
maxZoom: 22,
minPitch: 0,
maxPitch: 85,
- maxBounds: [-180, -85.051129, 180, 85.051129],
+ maxBounds: null,
projection: 'mercator',
renderWorldCopies: true,
};
Rationale:
nullis the natural identity for "prop was omitted, don't constrain" — matches maplibre-gl-js's own default (no bounds).map.setMaxBounds(null)is a no-op in maplibre'selsebranch (just clears_lngRange/_latRange), so it can't trigger the singular-matrix path.- It preserves the loop's correctness for the other settings, which are simple numeric / string defaults.
Alternative if maintainers want to preserve the existing intent: bounds strictly inside (-180, 180) longitude span (e.g. [-179.999, -85.051129, 179.999, 85.051129]) as upstream maplibre-gl-js#6148 suggests as a workaround. But null is cleaner.
Workaround for current downstream consumers
Always pass an explicit, stable value to <Map> so the prop never drops out of nextProps:
<Map
{...viewState}
maxBounds={null as never} // stable null short-circuits the DEFAULT_SETTINGS fallback
mapStyle={...}
/>
deepEqual(null, null) === true keeps the loop from entering the setter branch.
Environment
@vis.gl/[email protected](via[email protected])[email protected]- Firefox (primary repro), Chrome (forced repro via
WEBGL_lose_context)
Related upstream: maplibre/maplibre-gl-js#6148 (open).
- 主要语言
- TypeScript
- 星标
- 8.5k
- 派生
- 1.3k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
visgl/react-map-gl 的其他 Issue
-
[Bug] Mapbox geocoder example crashes: "i is not a function"可能已有人在做 @yuiseki 于 20 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
visgl/react-map-gl#2628 ·
-
[Bug] Scroll zoom stops short of maxZoom in controlled mode with MapLibre可能已有人在做 @sviat-barbutsa 于 33 天前认领。 未关闭bug
难度 3/5 半天 新手友好度 74/100
visgl/react-map-gl#2626 ·
-
[Bug] reuseMaps: Mapbox.reuse() infinite-loops (tab freeze) when the recycled map's container is the mount container可能已有人在做 @mikeyfarina 于 82 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
visgl/react-map-gl#2613 ·
-
feature
难度 5/5 一周以上 新手友好度 42/100
visgl/react-map-gl#2603 · 1 个 reaction ·
-
[Bug] Prop `style` does not unset properties that become `undefined`可能已有人在做 @MohammadYusif 于 140 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 66/100
visgl/react-map-gl#2595 · 3 条评论 ·
查看 visgl/react-map-gl 的全部 Issue
相似的 Issue
-
accessibility area:ci ci-test level:low priority:high type:test
难度 2/5 1-3 小时 新手友好度 71/100
skytuhua-org/Gen-V1#3132 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
drmrd/vernacular#1238 ·
维护者通常 1 天内回复
-
question
难度 2/5 1-3 小时 新手友好度 65/100
-
enhancement migration-prioritized
难度 2/5 1-3 小时 新手友好度 88/100
Hudson-Pufferfish/local-party-console#136 ·
维护者通常 1 天内回复
-
priority:medium
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复