-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 duplicate objects after restoring data from localStorage #2135
Conversation
Thanks for digging into this Martin. Can you explain what the problem is and the strategy this PR takes for fixing it? |
OK. We have the following situation: One edits in region A modifying object X (version v -> v+1) then closes the browser tab and later continues to edit in region B, using the restore tool. After the
Note the non-negative id X of the "created" way and that v > 1. The response from the OSM API is something like:
To solve this, I extended the |
@@ -292,8 +309,6 @@ iD.History = function(context) { | |||
|
|||
var json = context.storage(getKey('saved_history')); | |||
if (json) history.fromJSON(json); | |||
|
|||
context.storage(getKey('saved_history', null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line contained a typo (first parenthesis should close right after 'saved_history').
But then this would be quite contra-productive if the browser crashes right after restoring the data (before uploading or another change).
So, I simply dropped it.
I've also refactored the Entity class to use the
(note the v+1 instead of simply v as above) |
OK, the PR should be complete now. |
|
This makes sure that the originals of changed entities get merged into the base of the stack after restoring the data from JSON. This is necessary, because the stack will only have elements for the current viewport after a restart and previously *modified* objects will now be falsely detected as *created* ones. Also removed some ineffective code.
Oh, I see. (should have looked more at the inline documentation ^^). |
Ok, it took me a while to digest everything that was going on, but I think I have a good understanding now, and this approach looks sound. I see a couple adjustments to make:
|
Deleted objects need to be kept in the base of the history stack, too. This also improves the respective unit tests.
True: efd3223 |
fix duplicate objects after restoring data from localStorage
Attempt to fix #2134 (and possibly also #2091 and #1249).
This is not yet 100% finished, but can already be reviewed. Todos:restores from v2 JSON (modification)
testrestores from v3 JSON