Skip to content

Commit

Permalink
Fix bibliographyTest breakage after d5cf33a
Browse files Browse the repository at this point in the history
d5cf33a 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] zotero@99dd1c069776
[2] zotero@c2dd531cec4
  • Loading branch information
dstillman committed Apr 13, 2017
1 parent ed3b18b commit 9b53570
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions chrome/content/zotero/bibliography.js
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions chrome/content/zotero/xpcom/style.js
Expand Up @@ -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
Expand Down

0 comments on commit 9b53570

Please sign in to comment.