TiddlyWiki / TiddlyWiki5

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

Creating tiddlers with injected javascript causing type error in exports.getTiddlers #2782

Closed mgroth0 closed 7 years ago

mgroth0 commented 7 years ago

I am injecting javascript through a chrome extension in order to automate the creation of Tiddlers. For example:

$tw.wiki.addTiddler({
    title: [["Tell Me - GTA Remix -- Giraffage"]],
    spotify_uri: "spotify:track:4JqPCgla8OupgtITTKfKxS",
    duration: "0",
    track_number: "1",
    disc_number: "1",
    TiddlifyVersion: "0.1.0.0",
    tags: "electronic",
    text: "Artist: [[Giraffage]]<br>Album: [[No Reason Remixes|No Reason Remixes -- Giraffage]]\n\n<iframe src=\"https://embed.spotify.com/?uri=spotify%3Atrack%3A4JqPCgla8OupgtITTKfKxS\" width=\"700\" height=\"380\" frameborder=\"0\" allowtransparency=\"true\"></iframe>"
});

After using this to create a new tiddler, I start getting this error every time I try to edit any Tiddler or create a new tiddler:

Uncaught TypeError: a.fields[sortField].toLowerCase is not a function

I'm having trouble figuring out the cause of this error. Here's the full error trace:

$:/core/modules/wiki.js:277 Uncaught TypeError: a.fields[sortField].toLowerCase is not a function at eval ($:/core/modules/wiki.js:277:32) at Array.sort (native) at $tw.Wiki.exports.getTiddlers ($:/core/modules/wiki.js:276:11) at $tw.Wiki.exports.forEachTiddler ($:/core/modules/wiki.js:377:17) at $tw.Wiki.exports.findDraft ($:/core/modules/wiki.js:1160:7) at NavigatorWidget.makeDraftTiddler ($:/core/modules/widgets/navigator.js:290:29) at NavigatorWidget.handleEditTiddlerEvent ($:/core/modules/widgets/navigator.js:229:26) at eventListeners.(anonymous function) ($:/core/modules/widgets/widget.js:368:25) at NavigatorWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:385:7) at DropZoneWidget.Widget.dispatchEvent ($:/core/modules/widgets/widget.js:391:28)

The error keeps happening whenever I try to add or edit a tiddler after I use my javascript to create a tiddler.

Once I refresh the page everything is fine. The Tiddler I created is still there, and I can once again create and edit Tiddlers as long as I don't use the javascript that creates tiddlers.

buggyj commented 7 years ago

The format of the title is incorrect, use:

$tw.wiki.addTiddler({
    title: "[[\"Tell Me - GTA Remix -- Giraffage\"]]",

although I think you probably want

$tw.wiki.addTiddler({
    title: "Tell Me - GTA Remix -- Giraffage",
sukima commented 7 years ago

What @buggyj said; title should be a String not an Array(Array(String)). And avoid using square brackets in titles because that just leads to headaches.

mgroth0 commented 7 years ago

Problem solved, thanks! I should have noticed that, but since Tiddler titles were still coming out the way I wanted anyway even with the brackets, I didn't even consider it.

pmario commented 7 years ago

@matthew-groth please close the issue.