TiddlyWiki / TiddlyWiki5

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

Modifying tiddlers with tag $:/tags/Macro causes the Page to refresh #4456

Closed xcazin closed 11 months ago

xcazin commented 4 years ago

Editing macro tiddlers in the middle of the story river can therefore become annoying: each time the user saves such a tiddler, the Page is refreshed, which displays the top of the story instead of maintaining the focus near the tiddler that was modified.

As stated by Eric Shulman:

I suspect that it has to do with the way that global macros are loaded by the $:/core/ui/PageTemplate, which does the following: \import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]] This line causes an automatic refresh of the PageTemplate whenever a tiddler tagged with $:/tags/Macro is changed.

Jeremy added:

changing a global macro tiddler causes the entire page template to be reconstructed, losing the focus status.

xcazin commented 4 years ago

Note that such refresh may happen even if the tagged tiddler doesn't belong to the story river: for instance if another tiddler in the story displays <$checkbox tiddler="Macros archive outside the story river" tag="$:/tags/Macro"> Click here to activate/deactivate archived macros</$checkbox>, ticking the checkbox is enough for the page refresh mechanism to take place.

Jermolene commented 4 years ago

Hi @xcazin indeed the presence of the macro tiddler in the story river doesn't affect things: any change to a tiddler tagged $:/tags/Macro, including adding or removing that tag will cause pretty much the entire page template to be deleted and recreated as part of the next refresh cycle. When the story river itself is deleted and recreated we lose the scroll position.

This is a fundamental problem with the current design: we lose a lot of state from the DOM when widgets are deleted and recreated as part of the refresh cycle (selection status, focus, scroll positions, the state of summary/detail widgets etc).

The lack of state preservation is a major flaw that I’d like to see fixed. We have some proposals for partial solutions that work for some state in some situations, but we really need a rethink that makes state preservation just work across the board. One possibility is adopting a more conventional virtual DOM strategy for updating the DOM.

xcazin commented 4 years ago

Hi @Jermolene, thank you for this summary of the bigger picture.

pmario commented 11 months ago

@xcazin -- IMO this issue can be closed. It seems your question has been answered.

xcazin commented 11 months ago

@pmario Indeed!