TiddlyTools/Time/AutoSaver and Streams don't play well together?

66 views
Skip to first unread message

cmari

unread,
Oct 18, 2020, 8:00:36 PM10/18/20
to TiddlyWiki
I'd like to be able to use the features of both TiddlyTools/Time/AutoSaver and Streams. But after some experimenting, it seems that if I add both of these plugins to an otherwise empty 5.1.22 TW, when I try to use the (TiddlyTools) Autosaver option of "confirm before saving", I get the red javascript error ("Uncaught TypeError: Cannot read property 'toString' of null). Is there something I can do to prevent this error?
Thanks!
cmari

Eric Shulman

unread,
Oct 19, 2020, 1:31:50 AM10/19/20
to TiddlyWiki
On Sunday, October 18, 2020 at 5:00:36 PM UTC-7, cmari wrote:
I'd like to be able to use the features of both TiddlyTools/Time/AutoSaver and Streams. But after some experimenting, it seems that if I add both of these plugins to an otherwise empty 5.1.22 TW, when I try to use the (TiddlyTools) Autosaver option of "confirm before saving", I get the red javascript error ("Uncaught TypeError: Cannot read property 'toString' of null). Is there something I can do to prevent this error?

I took a look at the browser's debugging console, where it reports:
streams.html:13257 Uncaught TypeError: Cannot read property 'toString' of null

$tw
.utils.error @ streams.html:13257
$
:/plugins/sq/streams/selection-vars-tweak.js:29 Uncaught TypeError: Cannot read property 'toString' of null
    at
TimeoutWidget.Widget.invokeActionString ($:/plugins/sq/streams/selection-vars-tweak.js:29)
    at
eval (TiddlyTools/Time/action-timeout.js:40)

Here's a summary of what occurs:
  1. The TiddlyTools/Time/AutoSaver countdown timer is processed by the <<countdown_tick>> macro,
  2. which is defined in TiddlyTools/Time/CountDown and is called from TiddlyTools/Time/Ticker,
  3. which is invoked once per second by TiddlyTools/Time/action-timeout.js,
  4. which uses the TWCore "invokeActionString()" method.
  5. which has been "hijacked" by the Streams plugin code contained in $:/plugins/sq/streams/selection-vars-tweak.js,
Take note of these two lines from $:/plugins/sq/streams/selection-vars-tweak.js:
 if(activeElement && selection && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA")) {
 variables["selectionStart"] = activeElement.selectionStart.toString();

This is where the error actually occurs.

The problem is that the code is checking for activeElement.tagName === "INPUT", which is OK when the activeElement has a "selectionStart" property.  However, in the AutoSaver settings panel, the "confirm before saving" checkbox is also an HTML "input" element, but because it is not a *text* element, it has no "selectionStart" property. Thus, attempting to invoke "toString()" throws the "Uncaught TypeError: Cannot read property 'toString' of null" error that is reported in the browser's debugging console and by the TiddlyWiki RMOD ("Red Message of Death").


Often activeElement will return a HTMLInputElement or HTMLTextAreaElement object if it has the text selection at the time. If so, you can get more detail by using the object's selectionStart and selectionEnd properties. Other times the focused element might be a <select> element (menu) or an <input> element, of type "button", "checkbox", or "radio".

The fix is to change the code in $:/plugins/sq/streams/selection-vars-tweak.js to ensure that when the activeElement.tagName === "INPUT", the activeElement.type === "text", which would then exclude "button", "checkbox", or "radio" input elements.

Something like this will do the trick:
 if(activeElement && selection && ((activeElement.tagName === "INPUT" && activeElement.type === "TEXT") || activeElement.tagName === "TEXTAREA")) {

If you edit the $:/plugins/sq/streams/selection-vars-tweak.js shadow tiddler and change the line of code as shown above, that will bypass the problem until Saq can provide an update to the Streams plugin.

-e

Saq Imtiaz

unread,
Oct 19, 2020, 2:57:22 AM10/19/20
to TiddlyWiki
Thank you Eric. I'll push an update as soon as I get the chance.

Regards,
Saq

cmari

unread,
Oct 19, 2020, 11:22:18 AM10/19/20
to TiddlyWiki
Thank you so much, this is great - and thanks especially for the explanation.
cmari
Reply all
Reply to author
Forward
0 new messages