Skip to content

Leaflet .getSize() issue with Svelte #5988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gavinr opened this issue Feb 13, 2021 · 4 comments
Closed

Leaflet .getSize() issue with Svelte #5988

gavinr opened this issue Feb 13, 2021 · 4 comments
Labels
awaiting submitter needs a reproduction, or clarification

Comments

@gavinr
Copy link

gavinr commented Feb 13, 2021

Describe the bug
When creating a leaflet map, the leaflet getSize() function sometimes returns the wrong size within a Svelte app.

To Reproduce

  1. Clone this repo: https://github.com/gavinr/leaflet-custom-layer-issue
  2. npm install
  3. npm run build
  4. npm start

in a CHROMIUM-based browser (example: google chrome), open http://localhost:5000/ and refresh/hard-refresh a bunch of times until you see the "y" value in the developer console be an unreasonably small (~30 or 40) size.

Expected behavior

  • Expected: Size in the developer console should always be the same
  • Actual: sometimes on new refreshes the y value of the size is not correct (a very small number)

image

@antony
Copy link
Member

antony commented Feb 16, 2021

I'm not sure how this is an issue with Svelte. It seems that you're trying to get the size of a layer before it has properly rendered. It's a race condition.

@antony antony added the awaiting submitter needs a reproduction, or clarification label Feb 16, 2021
@gavinr
Copy link
Author

gavinr commented Feb 16, 2021

@antony thank you for the response. This works fine when not using Svelte - see https://github.com/gavinr/leaflet-custom-layer-issue/blob/master/public/standalone.html (sorry, should have included this in the original issue report), which is what makes me think it's an issue with Svelte.

@gavinr
Copy link
Author

gavinr commented Feb 18, 2021

It seems like the DOM or the styles sometimes have not fully loaded when this function gets called. Note I am using svelte actions here to call the function. When I use an action like this can I assume the DOM and styles are loaded? If not, what's a better way to guarantee that the the DOM and styles are loaded?

@Conduitry
Copy link
Member

You should be able to assume that the DOM and any styles are loaded, yes, but that's not to say that instantiating the LeafletMap instance has already synchronously done everything it's going to do to the DOM and that its getSize() method will return the desired values right away. If an element's size is affected by whether an image within it has finished downloading, that may also give you unexpected values. You're free to open another issue that shows something specifically wrong happening in Svelte, but for now, it looks like this issue involves you instantiating an external library and then after that calling a method on that external library and having an issue with its return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter needs a reproduction, or clarification
Projects
None yet
Development

No branches or pull requests

3 participants