Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions modules/react-mapbox/src/mapbox/mapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,6 @@
this.props = props;

const settingsChanged = this._updateSettings(props, oldProps);
if (settingsChanged) {
this._createProxyTransform(this._map);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pessimistress do you know why we had this?

}
const sizeChanged = this._updateSize(props);
const viewStateChanged = this._updateViewState(props, true);
this._updateStyle(props, oldProps);
Expand Down Expand Up @@ -502,7 +499,7 @@
@param {object} currProps
@returns {bool} true if anything is changed
*/
_updateStyleComponents(nextProps: MapboxProps, currProps: MapboxProps): boolean {

Check warning on line 502 in modules/react-mapbox/src/mapbox/mapbox.ts

View workflow job for this annotation

GitHub Actions / test-node

Method '_updateStyleComponents' has a complexity of 13. Maximum allowed is 11
const map = this._map;
let changed = false;
if (map.isStyleLoaded()) {
Expand Down
36 changes: 36 additions & 0 deletions modules/react-mapbox/test/components/map.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,42 @@ test('Map#controlled#no-update', t => {
);
});

test('Map#uncontrolled#delayedSettingsUpdate', async t => {
const root = createRoot(document.createElement('div'));
const mapRef = {current: null};

function App() {
const [settings, setSettings] = React.useState({
maxPitch: 85
});

async function onLoad() {
await sleep(1);
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using very short arbitrary sleeps (1ms) increases test flakiness; consider awaiting a specific condition (e.g., poll until mapRef.current.getMaxPitch() === 60) or using a higher-level helper instead of fixed tiny delays.

Copilot uses AI. Check for mistakes.
setSettings({maxPitch: 60});
}

return (
<Map
ref={mapRef}
mapLib={import('mapbox-gl-v3')}
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling import('mapbox-gl-v3') inside render will create a new Promise on every re-render when settings change. Memoize it (e.g., const mapLib = React.useMemo(() => import('mapbox-gl-v3'), []);) or move it outside the component to avoid repeated dynamic import calls.

Copilot uses AI. Check for mistakes.
mapboxAccessToken={MapboxAccessToken}
initialViewState={{longitude: -100, latitude: 40, zoom: 4}}
{...settings}
onLoad={() => {
onLoad();
}}
Comment thread
chrisgervang marked this conversation as resolved.
Outdated
/>
);
}

root.render(<App />);

await waitForMapLoad(mapRef);
await sleep(1);
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using very short arbitrary sleeps (1ms) increases test flakiness; consider awaiting a specific condition (e.g., poll until mapRef.current.getMaxPitch() === 60) or using a higher-level helper instead of fixed tiny delays.

Copilot uses AI. Check for mistakes.

t.is(mapRef.current.getMaxPitch(), 60, 'maxPitch is updated');
});

test('Map#controlled#mirror-back', t => {
const root = createRoot(document.createElement('div'));
const mapRef = {current: null};
Expand Down
Loading