Skip to content

Commit 00f9417

Browse files
authored
Fix/deckgl scenegraphlayer (#264)
MlScenegraphLayer props handling & deck.gl storybook demos Fixes a "Maximum update depth exceeded" bug in MlScenegraphLayer caused by improper props handling (the full props object was passed directly into useMemo, triggering infinite re-renders). Also fixes deck.gl storybook demos that were broken as a result.
1 parent dcf92c5 commit 00f9417

10 files changed

Lines changed: 3574 additions & 400 deletions

File tree

eslint.config.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,16 @@ export default [
102102
'**/*.cjs',
103103
'**/*.mjs',
104104
],
105-
rules: {},
105+
rules: {
106+
'@typescript-eslint/no-unused-vars': [
107+
'error',
108+
{
109+
argsIgnorePattern: '^_',
110+
varsIgnorePattern: '^_',
111+
destructuredArrayIgnorePattern: '^_',
112+
},
113+
],
114+
},
106115
},
107116
...storybook.configs['flat/recommended'],
108117
];

packages/deck-gl/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
"test": "echo \"Error: no test specified\" && exit 1"
1010
},
1111
"dependencies": {
12+
"@emotion/react": "^11.14.0",
13+
"@emotion/styled": "^11.14.1",
1214
"@mui/icons-material": "^7.3.2",
15+
"@mui/system": "^7.3.2",
1316
"@mui/material": "^7.3.2",
1417
"@storybook/react": "^9.1.4",
1518
"uuid": "^11.1.0"

packages/deck-gl/src/components/Ml3DTileLayer/Ml3DTileLayer.stories.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ PointCloudExample.parameters = {
2323
},
2424
};
2525
PointCloudExample.args = {
26-
mapId: 'map_1',
2726
id: 'PointCould',
2827
data: 'assets/tiles/tileset.json',
2928
pointSize: 2,
@@ -38,6 +37,5 @@ HamburgExample.parameters = {
3837
},
3938
};
4039
HamburgExample.args = {
41-
mapId: 'map_1',
4240
data: 'https://3dtiles.wheregroup.com/tileset.json',
4341
};

packages/deck-gl/src/components/MlHexagonLayer/MlHexagonLayer.stories.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const Template = (context: any) => {
6969
export const DefaultSettings: { [key: string]: any } = Template.bind({});
7070
DefaultSettings.parameters = {};
7171
DefaultSettings.args = {
72-
mapId: 'map_1',
7372
type: HexagonLayer,
7473
layerOpacity: 0.8,
7574
elevationRange: [30, 75],
@@ -93,7 +92,6 @@ DefaultSettings.args = {
9392
export const CustomColorAndHeightProfile: { [key: string]: any } = Template.bind({});
9493
CustomColorAndHeightProfile.parameters = {};
9594
CustomColorAndHeightProfile.args = {
96-
mapId: 'map_1',
9795
type: HexagonLayer,
9896
layerOpacity: 0.8,
9997
specularColor: [51, 51, 51],

packages/deck-gl/src/components/MlSceneGraphLayer/MlScenegraphLayer.stories.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ DeckglExample.parameters = {
7878
},
7979
};
8080
DeckglExample.args = {
81-
mapId: 'map_1',
8281
id: 'ScenegraphLayer',
8382
data: 'https://raw.githubusercontent.com/visgl/deck.gl-data/master/website/bart-stations.json',
8483
getPosition: (d: BartStation) => d.coordinates,
@@ -102,7 +101,6 @@ WhereGroupLocationExample.parameters = {
102101
},
103102
};
104103
WhereGroupLocationExample.args = {
105-
mapId: 'map_1',
106104
id: 'ScenegraphLayer',
107105
data: wgLocations,
108106
getPosition: (d: any) => d.geometry.coordinates,

packages/deck-gl/src/components/MlSceneGraphLayer/MlScenegraphLayer.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@ export interface MlScenegraphLayerProps extends ScenegraphLayerProps {
1616
}
1717

1818
const MlScenegraphLayer = (props: MlScenegraphLayerProps) => {
19-
const { mapId, ...ScenegraphLayerProps } = props;
20-
2119
const mapHook = useMap({
22-
mapId: mapId,
23-
waitForLayer: ScenegraphLayerProps.beforeId,
20+
mapId: props.mapId,
21+
waitForLayer: props.beforeId,
2422
});
2523
const deckGlHook = useDeckGl();
26-
const scenegraphLayer = useMemo(
27-
() =>
28-
new ScenegraphLayer({
29-
...ScenegraphLayerProps,
30-
}),
31-
[ScenegraphLayerProps]
32-
);
24+
const scenegraphLayer = useMemo(() => {
25+
const { mapId: _mapId, ...ScenegraphLayerProps } = props;
26+
return new ScenegraphLayer({
27+
...ScenegraphLayerProps,
28+
});
29+
}, [props]);
3330

3431
useEffect(() => {
3532
if (!mapHook.map || !scenegraphLayer) return;

packages/deck-gl/vite.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
99
export default defineConfig(() => ({
1010
root: __dirname,
1111
cacheDir: '../../node_modules/.vite/packages/deck-gl',
12+
resolve: {
13+
dedupe: [
14+
'react',
15+
'react-dom',
16+
'@mui/material',
17+
'@mui/system',
18+
'@emotion/react',
19+
'@emotion/styled',
20+
],
21+
},
1222
plugins: [
1323
react(),
1424
nxViteTsPaths(),
@@ -50,6 +60,11 @@ export default defineConfig(() => ({
5060
'@deck.gl/geo-layers',
5161
'@deck.gl/mapbox',
5262
'@deck.gl/mesh-layers',
63+
'@mui/material',
64+
'@mui/system',
65+
'@mui/icons-material',
66+
'@emotion/react',
67+
'@emotion/styled',
5368
],
5469
},
5570
},

packages/three/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"react-dom": "^19.1.0"
2121
},
2222
"dependencies": {
23+
"@emotion/react": "^11.14.0",
24+
"@emotion/styled": "^11.14.1",
2325
"@mui/material": "^7.3.2",
26+
"@mui/system": "^7.3.2",
2427
"maplibre-gl": "^5.16.0",
2528
"three": "^0.182.0"
2629
},

packages/three/vite.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
99
export default defineConfig(() => ({
1010
root: __dirname,
1111
cacheDir: '../../node_modules/.vite/packages/three',
12+
resolve: {
13+
dedupe: [
14+
'react',
15+
'react-dom',
16+
'@mui/material',
17+
'@mui/system',
18+
'@emotion/react',
19+
'@emotion/styled',
20+
],
21+
},
1222
plugins: [
1323
react(),
1424
nxViteTsPaths(),
@@ -51,6 +61,9 @@ export default defineConfig(() => ({
5161
'three',
5262
'maplibre-gl',
5363
'@mui/material',
64+
'@mui/system',
65+
'@emotion/react',
66+
'@emotion/styled',
5467
],
5568
},
5669
},

pnpm-lock.yaml

Lines changed: 3522 additions & 382 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)