Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
fix: GlobehexagonCellLayer crash from Babel unbound super calls (#3622)
Igor Dykhta29b8e47913f8
diff --git a/.cursor/rules/no-cast-super-calls.mdc b/.cursor/rules/no-cast-super-calls.mdcnew file mode 100644index 000000000..449ad7e8a--- /dev/null+++ b/.cursor/rules/no-cast-super-calls.mdc@@ -0,0 +1,25 @@+---+description: Never cast super.method before calling — Babel drops this+globs: **/*.{ts,tsx}+alwaysApply: false+---++# No cast-then-call on `super` methods++Do not write `(super.method as SomeType)(...)` or `(<SomeType>super.method)(...)`.++Babel compiles that to an unbound `_superPropGet(..., 1)` call, so `this` is+`undefined` and `this.props` crashes at runtime (kepler.gl #3614).++```ts+// Bad+const shaders = (super.getShaders as () => any)();+(super.draw as (o: any) => void)(opts);++// Good+const shaders = super.getShaders();+super.draw(opts);+```++If TypeScript complains about the super call signature, fix the types or use a+`// @ts-expect-error` on the call line — do not cast the method reference.diff --git a/src/deckgl-layers/src/globe/globe-view.ts b/src/deckgl-layers/src/globe/globe-view.tsindex 3fd208298..b547dcb60 100644--- a/src/deckgl-layers/src/globe/globe-view.ts+++ b/src/deckgl-layers/src/globe/globe-view.ts@@ -89,9 +89,6 @@ class ZoomToCursorGlobeController extends GlobeController {// view can't be centered on the poles. deck.gl's applyConstraints clamps// latitude to ~85°, which still lets the camera look straight at a pole.applyConstraints(props: any) {- // Avoid `(super.fn as any)(args)` — Babel compiles that to a property GET- // (`_superPropGet(..., 1)`) that drops `this`. A direct call uses method-CALL- // form (`_superPropGet(..., 3)`), which preserves the binding.const result = super.applyConstraints(props);const clampedLatitude = clamp(result.latitude, -GLOBE_MAX_LATITUDE, GLOBE_MAX_LATITUDE);if (clampedLatitude !== result.latitude) {diff --git a/src/deckgl-layers/src/layer-utils/globe-cell-utils.ts b/src/deckgl-layers/src/layer-utils/globe-cell-utils.tsindex 4afd99bc6..e56cb0894 100644--- a/src/deckgl-layers/src/layer-utils/globe-cell-utils.ts+++ b/src/deckgl-layers/src/layer-utils/globe-cell-utils.ts@@ -157,7 +157,7 @@ export function makeGlobeCellLayerClass<T extends LayerConstructor>(class GlobeCellLayer extends (BaseCellLayer as {new (...args: any[]): any}) {getShaders() {- const shaders = (super.getShaders as () => any)();+ const shaders = super.getShaders();return {...shaders,vs: addGlobeCellProjection(shaders.vs, type),@@ -175,7 +175,7 @@ export function makeGlobeCellLayerClass<T extends LayerConstructor>(if (model?.shaderInputs) {model.shaderInputs.setProps({globeCell: {globeMode}});}- (super.draw as (o: any) => void)(opts);+ super.draw(opts);}}(GlobeCellLayer as unknown as {layerName: string}).layerName = `Globe${type}CellLayer`;