joshuafontany / TW5-JsonMangler

A JSON extension plugin for TiddlyWiki5
https://joshuafontany.github.io/TW5-JsonMangler/
MIT License
15 stars 2 forks source link

Javascript errors under Node.js setups #3

Closed joshuafontany closed 5 years ago

joshuafontany commented 5 years ago

"Cannot read X of undefined" and other JS errors under Node.js setups (single server node and Bob multiserver).

More info from mauloop via GoogleGroups: https://groups.google.com/forum/#!topic/tiddlywiki/ZiFBwS_hplE

Hi, Joshua.

I run into troubles running Tiddlywiki with both Tiddlymap and JsonMangler plugins. I tested three different setups:

Tiddlywiki 5.1.19 on Node.js with plugins loaded via tiddlywiki.info Tiddlywiki 5.1.19 on Node.js with plugins addes as tid files (dragging links to plugin tiddlers from the demo web sites) Tiddliwiki 5.1.19 as a local stand-alone html file Both setups 1 and 2 don't work. As soon as I click on the map sidebar the following error is raised

https://groups.google.com/group/tiddlywiki/attach/18e55ee9f62ff/tmap+jsonmang-err1.JPG

After that clicking on any other tab results in an error like this one:

https://groups.google.com/group/tiddlywiki/attach/18e55ee9f62ff/tmap+jsonmang-err2.JPG

These are the messages logged in the browser console in the meantime:

 TiddlyWebAdaptor: Getting status 
$:/core/modules/utils/logger.js:33  TiddlyWebAdaptor: Status: {"username":"","anonymous":true,"read_only":false,"space":{"recipe":"default"},"tiddlywiki_version":"5.1.19"} 
$:/core/modules/utils/logger.js:33  syncer-browser-tiddlyweb: Retrieving skinny tiddler list 
2(index):1 Failed to load resource: the server responded with a status of 404 (Not Found)
$:/core/modules/utils/logger.js:33  syncer-browser-tiddlyweb: Dispatching 'save' task: $:/StoryList 
(index):11152 Uncaught TypeError: Cannot read property 'to' of undefined
$tw.utils.error @ (index):11152
$:/plugins/felixhayashi/tiddlymap/js/lib/utils/tmap:208 Uncaught TypeError: Cannot read property 'to' of undefined
    at Object.groupByProperty ($:/plugins/felixhayashi/tiddlymap/js/lib/utils/tmap:208)
    at Adapter.getAdjacencyList ($:/plugins/felixhayashi/tiddlymap/js/Adapter:215)
    at Adapter.getNeighbours ($:/plugins/felixhayashi/tiddlymap/js/Adapter:292)
    at Adapter.getGraph ($:/plugins/felixhayashi/tiddlymap/js/Adapter:428)
    at MapWidget.rebuildGraphData ($:/plugins/felixhayashi/tiddlymap/js/widget/MapWidget:812)
    at MapWidget.rebuildGraph ($:/plugins/felixhayashi/tiddlymap/js/widget/MapWidget:752)
    at MapWidget.initAndRenderGraph ($:/plugins/felixhayashi/tiddlymap/js/widget/MapWidget:980)
    at MapWidget.renderFullWidget ($:/plugins/felixhayashi/tiddlymap/js/widget/MapWidget:462)
    at MapWidget.render ($:/plugins/felixhayashi/tiddlymap/js/widget/MapWidget:393)
    at eval ($:/core/modules/widgets/widget.js:374)
$:/core/modules/utils/logger.js:33  syncer-browser-tiddlyweb: Retrieving skinny tiddler list 
(index):11152 Uncaught NotFoundError: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
$tw.utils.error @ (index):11152
$:/core/modules/widgets/reveal.js:45 Uncaught DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
    at RevealWidget.render ($:/core/modules/widgets/reveal.js:45:9)
    at RevealWidget.Widget.refreshSelf ($:/core/modules/widgets/widget.js:436:7)
    at RevealWidget.refresh ($:/core/modules/widgets/reveal.js:193:10)
    at eval ($:/core/modules/widgets/widget.js:446:27)
    at Object.$tw.utils.each (http://localhost:8080/:11089:12)
    at ListItemWidget.Widget.refreshChildren ($:/core/modules/widgets/widget.js:445:12)
    at ListItemWidget.refresh ($:/core/modules/widgets/list.js:317:14)
    at ListWidget.handleListChanges ($:/core/modules/widgets/list.js:224:38)
    at ListWidget.refresh ($:/core/modules/widgets/list.js:145:17)
    at eval ($:/core/modules/widgets/widget.js:446:27)
$:/core/modules/utils/logger.js:33  syncer-browser-tiddlyweb: Retrieving skinny tiddler list 
$:/core/modules/utils/logger.js:33  syncer-browser-tiddlyweb: Retrieving skinny tiddler list 
$:/core/modules/utils/logger.js:33  syncer-browser-tiddlyweb: Retrieving skinny tiddler list 

Config 3 seems to be working. Unfortunately I work with many wikis served by Node.js and config 1 is my favourite.

The wikis I used to test are fresh installation with no tiddlers other than the ones coming from the vanilla edition and the ones related to the plugins. Every test has been executed following the same steps in this order:

install Tiddlymap (with dependencies) Reload both server and browser page Open the map sidebar tab Switch some times between default and live view Install JsonMangler (with dependencies) Repeat steps 2-4 In all of the tests, troubles came up after step 5 (actually I am a long time user of Tiddlymap on Noder.js and I have never seen a behaviour like this before).

I also tried to remove Tiddlymap end reinstall it after Jsonmangler. It did not solve, but the TM plugin raised the "first run message" popup every time I reload the browser, despite I always clicked the OK button.

These are all of the infoes I was able to collect. I have no much JS developing experience to debug further. It is very frustrating since JsonMangler is very promising and could help me a lot. I hope @felixhayashi will be notified of this thread, since he could probably give us some useful suggestions.

Hope this feedback could help to improve the plugin. Best regards,

)+(au

joshuafontany commented 5 years ago

This seems to have been caused by one of the helper libraries (alphanum.js) adding a prototype method to the Array object type. This is a BAD IDEA as for (var x in arr) loops will also iterate these custom properties, breaking other people's code.

Commented out the custom protoype method, and made sure that 'alphanum' is required in each js file that uses it's methods.

joshuafontany commented 5 years ago

Closed. 2.0.4