Skip to content
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

Fixing useRef() usage in createElementHook to prevent unnecessary Leaflet object creation #1014

Merged
merged 2 commits into from
Aug 14, 2022

Conversation

abac
Copy link
Contributor

@abac abac commented Aug 4, 2022

  • WAS: createElement() factory called at every render, therefore nullifying any benefits of using MutableRefObject
  • NOW: createElement() factory called only if useRef() does not hold an already cached element object

- WAS: createElement() factory called at every render, therefore nullifying any benefits of using MutableRefObject
- NOW: createElement() factory called only if useRef() does not hold an already cached element object
@PaulLeCam
Copy link
Owner

Thanks but what's the purpose of this change please?

@abac
Copy link
Contributor Author

abac commented Aug 6, 2022 via email

@PaulLeCam
Copy link
Owner

Thanks for the details, ideally the createElement() call shouldn't be costly but I guess that's not always possible, so caching as you suggest sounds like a good idea.
Can you make sure the PR passes CI so II can merge it please?

@abac
Copy link
Contributor Author

abac commented Aug 6, 2022 via email

@PaulLeCam
Copy link
Owner

It's using ESLint, you should be able to reproduce the issue by running the "lint" script from the root package.json.

@abac
Copy link
Contributor Author

abac commented Aug 7, 2022

Thanks for the pointer, Paul. Lint should be happy now.

@PaulLeCam PaulLeCam merged commit fd9fde6 into PaulLeCam:master Aug 14, 2022
@PaulLeCam
Copy link
Owner

Thanks!

@sherl0cks
Copy link

sherl0cks commented Aug 17, 2022

@PaulLeCam be advised that my team has a react-leaflet v3 app with lots of geojson layers that can be dragged around. This bug results in significant performance issues in under these conditions, which led us to write our own geojson component using the core API, but not the higher order hooks.

@abac Thank you very much for fixing this issue! I spent a considerable amount of time trying to find it but could not!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants