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

Fix Path.setStyle bug (replacing #6671) #6941

Merged
merged 13 commits into from Oct 29, 2021
Merged

Fix Path.setStyle bug (replacing #6671) #6941

merged 13 commits into from Oct 29, 2021

Conversation

NielsHolt
Copy link
Contributor

@NielsHolt NielsHolt commented Dec 14, 2019

This is a new PR replacing #6671

Fix issue #6662 and #6664

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

This looks good, but I agree it would nice to have a unit test to make sure we don't regress in future.

@johnd0e johnd0e changed the title Fix issue #6662 and #6664 Fix Path.setStyle bug (replacing #6671) Apr 16, 2020
@NielsHolt
Copy link
Contributor Author

Hi @mourner and @IvanSanchez
Do you know when you expect this PR to be included in a patch?
Kind regards
Niels

@naedx
Copy link

naedx commented May 14, 2020

Hi @mourner and @IvanSanchez
Do you know when you expect this PR to be included in a patch?
Kind regards
Niels

Hi guys, are there any updates on merging this?

@NielsHolt
Copy link
Contributor Author

Hi @mourner and @IvanSanchez
I see that this PR was not included in 1.7.1
Do you know when you expect this PR to be included in a patch?
It fixes a bug that was introduced in version 1.5 so I would urge you to please include it in the next patch.

Kind regards
Niels

@johnd0e
Copy link
Collaborator

johnd0e commented Sep 19, 2020

@NielsHolt

  1. Resolve conflicts
  2. Add unit test

Add unit test for Path weight set error
@fodor0205
Copy link
Contributor

The error only occurs with the following order:

  1. Polyline added to the map
  2. setStyle() called with weight

The description in #6662 does not seem to be correct, because no error occurs if setStyle is called before addTo().

@johnd0e
Copy link
Collaborator

johnd0e commented Jan 20, 2021

The description in #6662 does not seem to be correct, because no error occurs if setStyle is called before addTo().

But it is not about description only, as there is code in steps to reproduce section:

var polyline = L.polyline([[45.51, -122.68],[37.77, -122.43],[34.04, -118.2]]);
polyline.setStyle({color: 'red', weight: 4});
polyline.addTo(map);

And I do not see any problem even if I call setStyle after adding to map.

@johnd0e
Copy link
Collaborator

johnd0e commented Jan 20, 2021

So I am able to see that only #6664 issue is relevant, and there described slightly different case:

  • polygon/polyline is empty
  • setStyle is called after feature added to map.

Ok, then I have more questions:

  1. As test is not specific to Polyline, shouldn't we place to place into PathSpec.js?
  2. Doesn't other shapes suffer from the issue?
  3. Isn't there some performance loss on replacing this._updateBounds with _project call?
    I'm afraid that here we are fixing only empty polygon/line - very particular and unlikely case - at the cost of overall performance of every L.Path's descendant.

@fodor0205
Copy link
Contributor

fodor0205 commented Jan 25, 2021

As test is not specific to Polyline, shouldn't we place to place into PathSpec.js?
Doesn't other shapes suffer from the issue?

5 vector overlays extend Path:

  • Polyline and Polygon are affected:

    They have unit test in my branch referenced below, which perfectly trigger the bug.

  • Rectangle is not affected:

    Rectangle has no option to initialize with empty values, so this offending code-path can never be reached. (an Error is throw during initialization with empty values)

  • CircleMarker and Circle are not affected:

    The reference to undefined variable _this._rawPxBounds is located in Polyline's _updateBounds() function, not inside any classes reached on this chain.

A possible fix without touching Path.js:
master...fodor0205:master

Isn't there some performance loss on replacing this._updateBounds with _project call? I'm afraid that here we are fixing only empty polygon/line - very particular and unlikely case - at the cost of overall performance of every L.Path's descendant.

The alternative fix linked above only changes the offending code-path, making less impact in other use cases.

@johnd0e @NielsHolt Could you please review this alternative fix?

Edit: added info about Polygon, Rectangle and Circle.

@johnd0e
Copy link
Collaborator

johnd0e commented Jan 26, 2021

The alternative fix linked above only changes the offending code-path, making less impact in other use cases.

I still doubt that it makes sense to project empty polyline.
How about simpler fix:

		if (!this._rawPxBounds) { return; }

@fodor0205
Copy link
Contributor

This solution makes more sense @johnd0e, I have updated my branch, waiting for @NielsHolt to pull it into his branch, so it will be available in this PR.

Alternative fix for setting weight after empty Polyline or Polygon is added to the map
@NielsHolt
Copy link
Contributor Author

Hi
Thanks! The fix from @fodor0205 seems to fix the issue.
I have merged the PR into my master, but I am not sure what to do next except wait for the leaflet guys to include the PR?

NielsHolt added a commit to FCOO/leaflet-bugfix that referenced this pull request Jan 29, 2021
@fodor0205
Copy link
Contributor

@johnd0e do you think this is ready to be merged?

@johnd0e
Copy link
Collaborator

johnd0e commented Feb 3, 2021

Waiting for FCOO#4

Minor refactoring of tests
@fodor0205
Copy link
Contributor

What's the next step? @johnd0e

Copy link
Collaborator

@johnd0e johnd0e left a comment

Choose a reason for hiding this comment

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

It is ready for merge, so waiting @mourner or @IvanSanchez.

@contibru
Copy link

Is there any due date for this issue?

@mourner mourner merged commit 2eb73c4 into Leaflet:master Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants