Skip to content

Commit

Permalink
Fix map loading bug introduced by test loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Brody committed Sep 17, 2024
1 parent 5d1f3c9 commit 92b54ab
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions react/src/components/map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class MapGeneric<P extends MapGenericProps> extends React.Component<P, Ma
zoomSnap: this.delta, zoomDelta: this.delta, wheelPxPerZoomLevel: 60 / this.delta,
})
this.map = map
await this.componentDidUpdate()
await this.componentDidUpdate(this.props, this.state)
}

/**
Expand Down Expand Up @@ -186,8 +186,11 @@ export class MapGeneric<P extends MapGenericProps> extends React.Component<P, Ma
return JSON.stringify(geojson)
}

override async componentDidUpdate(): Promise<void> {
await this.updateToVersion(this.version + 1)
override async componentDidUpdate(prevProps: P, prevState: MapState): Promise<void> {
if (this.version === 0 || JSON.stringify(prevProps) !== JSON.stringify(this.props) || JSON.stringify({ ...prevState, loading: undefined }) !== JSON.stringify({ ...this.state, loading: undefined })) {
// Only update if something that's not the loading has changed, or it's the first load
await this.updateToVersion(this.version + 1)
}
}

async updateToVersion(version: number): Promise<void> {
Expand Down

0 comments on commit 92b54ab

Please sign in to comment.