felixhayashi / TW5-TiddlyMap

Map drawing and topic visualization for your wiki
http://tiddlymap.org
BSD 2-Clause "Simplified" License
845 stars 127 forks source link

[BUG] Plugin Deleted all contents of tiddlers #431

Closed Fllamber closed 1 year ago

Fllamber commented 1 year ago

I Installed the plugin with all dependencies in nodejs, but when chrome loaded the page

gave an error at: tiddlymap/map/js/lib/utils/tmap.js

var a = wikiUtils.getTiddler(t);
r = r || a.fields.type || "image/svg+xml";

Type Error : a is undefined.

then all my tiddlers were modified, they have now a field called 'tmap.id' with an hash, but no content.

Please, if your plugin will change the users files, make sure an error does not delete its contents in mass. No other plugin does this, and there were no backup warnings, or indication that this would happen.

Give a warning that the files are being converted / will be converted or read a file where the user has to type 'Yes' to agree with modifications.

flibbles commented 1 year ago

Wow. That really sucks. I hope you had a backup.

You wouldn't happen to have had Lazy Loading enabled, would you? That's the only reason I can think that TiddlyMap might do this.

Also, which version of TiddlyMap did you have? Was this the version on tiddlyMap.org? Or did you get it from github here recently?

Fllamber commented 1 year ago

I had lazy loading enabled. I had a parcial backup, it was only a week of damage. It was the version from github. I downloaded everything yesterday.

  "version": "0.17.14+10018",
  "released": "Sat, 10 Sep 2022 14:33:22 GMT",

Thanks for reading the issue @flibbles, next time I will be more carefull with plugins.

Just for the record:

the First error, with Lazy Loading tiddlymap/map/js/lib/utils/tmap.js

var a = wikiUtils.getTiddler(t);
r = r || a.fields.type || "image/svg+xml";

Firefox:

TypeError: a is undefined

Chrome:

Uncaught TypeError: Cannot read properties of undefined (reading 'fields')

Without Lazy Loading: hotzone/hotzone.js var d = r.children; Firefox:

TypeError: r is undefined

Chrome:

Uncaught TypeError: Cannot read properties of undefined (reading 'children')

flibbles commented 1 year ago

So the error you're seeing of the error and of the deletion of your tiddlers is related, but one is not causing the other. It's the lazy loading. Even in core TW, it has a nasty bug where it deletes a tiddler's text content if anything changes it before it's loaded from the server (such as adding a tmap.id field). I've reported it to the core years ago, but it doesn't seem like anyone is going to fix it. Lazy loading is just buggy and bad.

But it was made so much worse by TiddlyMap because of its design decision to add a tmap.id to every single tiddler upon first loading, which is frankly, and regrettable design decision which made a lot more sense back in 2016 when there was no mechanism for handling tiddler title changes, and the author of this plugin needed a way to integrate tiddlers with graphs and edges without all that breaking on a rename. The error you're getting is probably resulting from the tiddler not fully existing when TiddlyMap is trying to do something, but as far as I can tell, that part of the code is actually separate from the tmap.id propagation. I'll leave this issue open for now, and see sometime if I can at least warn users if they have lazy loading enable, even if the best I could do then is disable TiddlyMap until otherwise.

Realistically, the best fix for this would be to get rid of the concept of tmap.id now that TW has evolved enough that it's not needed, but that would involve rewriting major parts of TiddlyMap, and I do not know the code base well enough for that.

Once again, my condolences on losing so much of your work. I would advise you not to use Lazy Loading, because other plugins may trip the same bug too. (I know I originally found it because my Relink plugin would inadvertently erase everyone's content if it did any relinking in unloaded tiddlers. The best I could do was warn people not to use Lazy Loading with Relink.)

flibbles commented 1 year ago

Turns out the exception was completely unrelated. It's tied issue #432 which somebody else reported today. The latest source code now has that fixed.

As for the tiddler deletion, I've opened pull request https://github.com/Jermolene/TiddlyWiki5/pull/7014 for TW core which should prevent this sort of thing from happening again. That fix won't get in until the next TW release, assuming it gets merged in time.

But even with that fix, I'm not sure I recommend using lazy-loading with TiddlyMap. Some features such as magic edges (e.g. "body links") won't work correctly while it's enabled.

I'll keep this issue open for now until the fix has been merged into core.

flibbles commented 1 year ago

I am closing out this issue. The fix has been merged into core.

It took somebody else getting all their images deleted through the lazy-images mechanism in an unrelated plugin before it got enough attention, but it got in.