TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
7.97k stars 1.18k forks source link

[BUG] Browser storage plugin does not remove deleted overwritten shadow tiddlers from storage #7364

Closed btheado closed 1 year ago

btheado commented 1 year ago

Describe the bug

When using the browser storage plugin and a shadow tiddler is overwritten and that tiddler is written to browser storage, then deleting the tiddler does not remove it from local storage. The only way to remove it is to use developer tools and manually remove the local storage entry.

Expected behavior

When an overwritten shadow tiddler is deleted, it should also be deleted from local storage.

I haven't fully thought through how to fix yet. It might work to check if the changed tiddler only exists as a shadow tiddler, then its key should be deleted from local storage.

To Reproduce

  1. Go to https://tiddlywiki.com/editions/full/#%24%3A%2Fconfig%2FBrowserStorage%2FSaveFilter:%24%3A%2Fplugins%2Ftiddlywiki%2Fbrowser-storage%20%24%3A%2Fconfig%2FBrowserStorage%2FSaveFilter%20%24%3A%2Fconfig%2FDefaultMoreSidebarTab
  2. Change the browser storage save filter to be more liberal with the tiddlers it saves: [all[]] -[is[shadow]!is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]]
  3. Make some change the value in the $:/config/DefaultMoreSidebarTab shadow tiddler. This will cause the overwritten shadow tiddler to be saved to local storage
  4. Delete the overwritten shadow tiddler
  5. Refresh the page and notice the overwritten shadow tiddler comes back in spite of its previous deletion.

Screenshots

No response

TiddlyWiki Configuration

5.2.6 prerelease (the issue is nothing new to this version...it has always been there)

Additional context

No response

btheado commented 1 year ago

I think the issue is related to the save filter I'm using. Specifically this part: -[is[shadow]!is[tiddler]]. Without it, installing a plugin results in all the shadow tiddlers in that plugin to "explode" individually into browser storage. However, I suspect this filter is also preventing the overwritten shadow tiddler from being deleted from local storage. I need to investigate more.

Jermolene commented 1 year ago

Thanks @btheado this is an interesting problem. If nothing else it would be good to update the docs to note any pitfalls in composing the browser storage save filter.

btheado commented 1 year ago

I created a PR which has what I think is a reasonable fix. I changed the javascript to prevent shadow tiddlers from being saved to local storage. That seems reasonable to me...I haven't been able to think of a use case for saving shadow tiddlers. Hopefully I'm not missing anything. Of course, saving overwritten shadow tiddlers is useful and that still works fine.