From 29b5b064d6742de38edebad9afd47f78639c12dc Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Thu, 6 Jul 2023 09:56:39 +0100 Subject: [PATCH 1/2] Robustify widget.removeLocalDomNodes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we get crashes if the DOM nodes generated by a widget have been subsequently modified by something like MathJax – see https://talk.tiddlywiki.org/t/tw-5-3-0-js-exception/7488/2 --- core/modules/widgets/widget.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index 0394c636f..1e6beae25 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -750,7 +750,9 @@ Widget.prototype.removeLocalDomNodes = function() { // If this widget has directly created DOM nodes, delete them and exit. if(this.domNodes.length > 0) { $tw.utils.each(this.domNodes,function(domNode) { - domNode.parentNode.removeChild(domNode); + if(domNode.parentNode) { + domNode.parentNode.removeChild(domNode); + } }); this.domNodes = []; } From 6c7c21a87bdb0d8a00df1c14eea18912164e0b57 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Thu, 6 Jul 2023 11:52:33 +0100 Subject: [PATCH 2/2] Fix overeager onload handler in Jasmine plugin All of this is needed to enable the Jasmine plugin to work in environment with an asynchronous startup, as seen in the sqlite3 wiki store --- plugins/tiddlywiki/jasmine/jasmine-plugin.js | 10 ++++++++-- plugins/tiddlywiki/jasmine/startup.js | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/tiddlywiki/jasmine/jasmine-plugin.js b/plugins/tiddlywiki/jasmine/jasmine-plugin.js index 7da00af75..fb851865b 100644 --- a/plugins/tiddlywiki/jasmine/jasmine-plugin.js +++ b/plugins/tiddlywiki/jasmine/jasmine-plugin.js @@ -94,7 +94,11 @@ exports.runTests = function(callback,specFilter) { if($tw.browser) { window.jasmineRequire = jasmineCore; $tw.modules.execute("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/jasmine-html.js"); + var previousOnloadHandler = window.onload; + window.onload = function() {}; $tw.modules.execute("$:/plugins/tiddlywiki/jasmine/jasmine-core/jasmine-core/boot.js"); + var jasmineOnloadHandler = window.onload; + window.onload = function() {}; jasmine = window.jasmine; } else { // Add missing properties to `jasmineCore` in order to call the Jasmine @@ -144,9 +148,11 @@ exports.runTests = function(callback,specFilter) { // Iterate through all the test modules var tests = $tw.wiki.filterTiddlers(TEST_TIDDLER_FILTER); $tw.utils.each(tests,evalInContext); - // In a browser environment, jasmine-core/boot.js calls `execute()` for us. + // In a browser environment, we use jasmine-core/boot.js to call `execute()` for us. // In Node.js, we call it manually. - if(!$tw.browser) { + if($tw.browser) { + jasmineOnloadHandler(); + } else { nodeJasmineWrapper.execute(null,specFilter); } }; diff --git a/plugins/tiddlywiki/jasmine/startup.js b/plugins/tiddlywiki/jasmine/startup.js index 46f9ef470..47aec342d 100644 --- a/plugins/tiddlywiki/jasmine/startup.js +++ b/plugins/tiddlywiki/jasmine/startup.js @@ -17,8 +17,9 @@ var jasmine = require("./jasmine-plugin.js"); exports.name = "jasmine"; if($tw.browser) { - // Jasmine is run automatically on the browser, so always add it here. exports.startup = jasmine.runTests; + exports.before = ["render"]; + exports.after = ["story"]; } else { // However, if we're on node.js, the tests are explciitly run with the // --test command. This didn't used to be the case, so if they're