TW5 port of github.com/json-editor/json-editor

60 views
Skip to first unread message

Joshua Fontany

unread,
Mar 15, 2019, 3:17:37 PM3/15/19
to TiddlyWikiDev
I'm experimenting with rendering UI by setting up JSON Schemas. There was an old TW port of one of the earlier versions of this project, and I was able to import the currently maintained module into that plugin.

Than I discovered that there is a race condition bug in how the jsoneditor manipulated the DOM vs how TW manipulates the DOM. I scanned through the docs and sourcecode a while, and it seems like they have built this modularly enough that I can change the "rendering engine" file for each Input type and make them render native TW widgets. I will have to cut out all of json-editor's native messaging code and just rely on the TW refresh and get/setTextReference functions.

This seems doable, but wanted to see if anyone has run into any 'gotchas' or roadblocks in similar cases...

origin: https://github.com/json-editor/json-editor

previous TW plugin: https://github.com/btheado/jsoneditor

current TW plugin (broken, does not push json updates back to TW):
https://github.com/joshuafontany/TW5-jsoneditor

current Example wiki:
https://joshuafontany.github.io/TW5-jsoneditor/ 

Best,

Joshua Fontany

Brian Theado

unread,
Mar 16, 2019, 4:47:12 PM3/16/19
to tiddly...@googlegroups.com
Joshua,

> there is a race condition bug in how the jsoneditor manipulated the DOM vs how TW manipulates the DOM

Could you share the details on that?

That was the first TW plugin I wrote. Being a little new I found it annoying not to be able to use a field in the same tiddler to store the output json (in fact if no text reference is passed in, the default is a field on the current widget) and so I tried to code around it and make it work for that case. I think that was a mistake and I could easily see it causing some kind of problems. Could that be the source of your issue?

Brian

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/65200232-3d7d-448e-a741-c3a652d60cca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joshua Fontany

unread,
Mar 16, 2019, 5:52:17 PM3/16/19
to TiddlyWikiDev
Reproduction Steps:

1. Load up https://btheado.github.io/jsoneditor.html
2. Go to the "Degenerate case: no schema specified" example
3. Change the root to "array" and add 1 item.
4. Set the first array item to type "boolean".
5. Set the first array item to type "number".
6. Set the first array item to type "boolean".

Observed Results:
Step 4: The schema at the bottom reads `[false]`, but the UI item renders `null`.
Step 5: The schema at the bottom reads `[""]`, and the UI item renders correctly.
Step 6: The schema at the bottom reads `[false]`, but the UI item renders `null`.


Best I could tell from the symptoms, there is something going on where the editor widget confirms the edit and writes the JSON. This triggers TW's refresh mechanism. When it gets to your `JSONEditorWidget.prototype.refresh` function it detects that the SCHEMA value of the options has changed, which triggers `this.refreshSelf();`. This appears to trigger TW's refresh cycle again, causing the selected option to be written - but the UI is using the previous version of the schema. Really weird case. I'm going to read through the guts of JSONEditor's core.js file and also the "./editors/*" functions to see if we can get it to spawn native TW input widgets (which will automatically handle writing the data to the target for you with the TW input mechanism), and disable JSONEditor's internal refresh mechanism. We'll see how that goes...
Best, Joshua F

Brian Theado

unread,
Mar 17, 2019, 10:11:50 PM3/17/19
to tiddly...@googlegroups.com
Joshua,

Thanks for the details. Using your procedure, I am able to reproduce the same issue. I'm still thinking the issue is using fields in the same tiddler to store the json output. I plan to rewrite the usage demo so it only uses other tiddlers to store the output. If that helps then I will remove the code which attempts to support that mode of operation and document that the use should avoid this approach. I think that is the simplest solution.

Brian

Reply all
Reply to author
Forward
0 new messages