Skip to content

Removing saved data from storage on submit with low save delay #544

@Furgas

Description

@Furgas

When autosave delay is low (few seconds - but it depends on server speed), autosave can kick in after submit event listener was processed and value was removed from local storage. So, the item will be inserted to local storage again. Clearing the timeout in listener fixes this issue for me:

SimpleMDE.prototype.autosave = function() {
//...
	if(this.options.autosave.binded !== true) {
		if(simplemde.element.form != null && simplemde.element.form != undefined) {
			simplemde.element.form.addEventListener("submit", function() {
				clearTimeout(simplemde.autosaveTimeoutId);
				simplemde.autosaveTimeoutId = undefined;

				localStorage.removeItem("smde_" + simplemde.options.autosave.uniqueId);

				//restart autosaving in case the submit will be cancelled down the line
				setTimeout(function() {
					simplemde.autosave();
				}, 30000);
			});
		}

		this.options.autosave.binded = true;
	}
//...
};

Should I create a pull request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions