commit 9b535709684c1945904feb49082569579b8d4cd0
parent ed3b18ba8c62ef22e71c5c724e1d7287a812b933
Author: Dan Stillman <dstillman@zotero.org>
Date: Thu, 13 Apr 2017 04:19:55 -0400
Fix bibliographyTest breakage after d5cf33a798
d5cf33a798 adds a `yield` to bibliography.js, which runs in modal
windows (e.g., Create Bib), but there's a weird interaction between
Bluebird and modal dialogs that can result in hangs -- presumably
something to do with things being queued on the event loop but the modal
dialog preventing other code from running? This was breaking
bibliographyTest, but it seemed to work fine for me in normal usage,
waiting properly for a running styles initialization to finish. It's
possible this problem is limited to tests, but in the past, at least, I
apparently decided that this was a general problem with `yield` in modal
dialogs [1]. (See also: [2].) In any case, calling `yield
Zotero.Styles.init()` from the Create Bib window was hanging the test,
so for now do a synchronous check for style initialization to avoid it,
and we should make sure that `yield` actually works in other contexts.
[1] https://github.com/zotero/zotero/commit/99dd1c069776
[2] https://github.com/zotero/zotero/commit/c2dd531cec4
Diffstat:
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js
@@ -67,8 +67,11 @@ var Zotero_File_Interface_Bibliography = new function() {
_io.style = Zotero.Prefs.get("export.lastStyle");
}
- // Initialize styles
- yield Zotero.Styles.init();
+ // See note in style.js
+ if (!Zotero.Styles.initialized) {
+ // Initialize styles
+ yield Zotero.Styles.init();
+ }
// add styles to list
diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js
@@ -117,6 +117,14 @@ Zotero.Styles = new function() {
});
this.init = Zotero.lazy(this.reinit);
+ // This is used by bibliography.js to work around a weird interaction between Bluebird and modal
+ // dialogs in tests. Calling `yield Zotero.Styles.init()` from `Zotero_File_Interface_Bibliography.init()`
+ // in the modal Create Bibliography dialog results in a hang, so instead use a synchronous check for
+ // initialization. The hang doesn't seem to happen (at least in the same way) outside of tests.
+ this.initialized = function () {
+ return _initialized;
+ };
+
/**
* Reads all styles from a given directory and caches their metadata
* @private