question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unpredictable resizing behaviour

See original GitHub issue

First of all, let me thank you for this library. We just switched to it from uber/react-map-gl and are much happier with it. In particular, the cluster and inertia panning functionalities are great.

One thing that we are still struggling with is the auto-sizing functionality, which worked better with uber. We are using <Autosizer> from the https://github.com/bvaughn/react-virtualized library to dynamically adjust the map for responsive designs.

Our code looks basically like this:


<AutoSizer>
            {({ height, width }) => {
              return (
                  <MapGL
                    ref={this.map}
                    style={{ width, height }}
                    {...this.state.viewport}
                    mapStyle={`https://api.maptiler.com/maps/basic/style.json?key=${key}`}
                    onViewportChange={this.onViewportChange}
                    viewportChangeMethod={viewportChangeMethod}
                    viewportChangeOptions={viewPortChangeOptions}
                    onClick={onClick}
                  >
            );
      }}
</AutoSizer>

With this code, the map sometimes gets very small (or isn’t even visible), sometimes it’s just a bit too small. We’ve noticed that <AutoSizer> sometimes reports wrong sizes for a moment (like height or width being 0), but it catches up and then uses the correct sizes. It seems as if your library cannot keep up with this. It looks as if some debouncing is happening inside the library, but it doesn’t work well.

We added some safeguarding code that checks for width or height being 0 and re-using the previous sizes instead. This helped a bit, but did not completely solve our problem.

The problem is most prominent if you toggle Chrome’s developer tools on and off. Without the safe-guarding code, sometimes the map disappears completely, or it is only 20px high.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
oselzcommented, Apr 30, 2020

@derwaldgeist I never had much luck getting AutoSizer working perfectly either, as a workaround we use react-sizeme to force a map resize. It is not the cleanest, but is reliable:

import { withSize } from 'react-sizeme'

const SizeAware = withSize({ noPlaceholder: true, monitorHeight: true })(
    (props => props.children) as React.ComponentType<any>,
)

class ReactMap extends React.Component<MapProps, MapState> {
    reactMap: any

    constructor(props: any) {
        super(props)
        this.reactMap = React.createRef()
    }
    resizeMap = () => {
        this.reactMap.current.getMap().resize()
    }
    render = (): React.ReactNode => {
        return (
            <SizeAware onSize={this.resizeMap}>
                <MapGL
                    ref={this.reactMap}
                    trackResize={false}
                 >
                    {children}
                </MapGL>
            </SizeAware>
        )
    }
}
1reaction
derwaldgeistcommented, Jun 23, 2020

@cazzer Thanks for taking your time to provide a repro, that’s awesome. I just wanted to let you know that I can’t actually see this on Stackblitz. It reports the @urbica/react-map-gl library as being missing. Maybe it’s just on my end, but I thought it would be worth mentioning.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Completely unexpected behaviour on resize - Construct 3
I'm stretching a sprite width do match WindowWidth, the resulting width is completely unpredictable and doesn't correspond with reality.
Read more >
Unstable and unpredictable windows sizing when splitting windows
The splitting behaviour seems to upset by manually resizing the windows. If you resize a window then start adding and removing splits things...
Read more >
Ticket #15837 (closed defect: fixed) - VirtualBox
Guest application window resizing behaves inconsistently while in seamless ... or other app) results in unexpected resizing behavior when in seamless mode.
Read more >
Manually resizing a running cluster - Amazon EMR
You can use the Amazon EMR console to resize a running cluster. ... Terminating an instance in this way risks data loss and...
Read more >
Why is browser behaviour "unpredictable" for this CSS/HTML ...
But it makes my browser behave unpredictably. Sometimes there is no effect on hover, sometimes a delayed effect, or the effect is only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found