Jermolene / TiddlyWiki5

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

edit button for appending a datestamp throws js error #2258

Open tobibeer opened 8 years ago

tobibeer commented 8 years ago

Haven't done any debugging yet, but I didn't expect this to throw a red js error box:

title: $:/_my/ui/Buttons/datestamp
tags: $:/tags/EditToolbar

\define button()
<$button>
<$action-setfield $field="text" $value="""$(currentText)$

$(dateStamp)$"""/>
{{$:/core/images/new-journal-button}}
</$button>
\end

<$vars currentText={{!!text}} dateStamp=<<now "YYYY-0MM-0DD">>>
<<button>>
</$vars>
Jermolene commented 8 years ago

The error is "maximum call stack exceeded", in other words, a recursive loop. It's happening because you are attempting to view the edit toolbar button on itself, pointing at it's own text. I don't think you'd get the error if we could avoid viewing this tiddler in view mode.

One way you might want to experiment with debugging this is to explore a feature I've thought of before; making all system tiddlers display by default as monospaced, unwikified text. To preserve existing behaviour we'd have to whitelist $:/ControlPanel and a few others, but roughly speaking, one usually wants to look at the source of system tiddlers, not view them wikified. This is essentially the same problem as the errors you get viewing the raw page template tiddler, and would be fixed in the same way.

tobibeer commented 8 years ago

@Jermolene, yes, of course. Makes sense.

Two questions:

1) Why would this produce an error even if the action never gets triggered?

2) I now modified it to:

title: $:/_my/ui/Buttons/datestamp
tags: $:/tags/EditToolbar

\define button()
<$button>
<$action-setfield $field="text" $value="""$(currentText)$$(dateStamp)$"""/>
{{$:/core/images/new-journal-button}}
</$button>
\end

<$list filter="[all[current]has[draft.of]]">
<$vars currentText={{!!text}} dateStamp=<<now "YYYY-0MM-0DD">>>
<<button>>
</$vars>
</$list>

If I now re-open this button in edit-mode, I get the same call-stack error. Why is that?

twMat commented 8 years ago

Thanks for posting this @tobibeer (ref )

@Jermolene wrote:

I don't think you'd get the error if we could avoid viewing this tiddler in view mode.

I just tried this using the SideEditor and, yes, it does seem to work when the tiddler is closed.

(Same thing for second version @tobibeer just posted above here.)