From 5b82a38383ee2689b959c656713beb3e8accdea6 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Tue, 21 Oct 2025 11:27:01 -0400 Subject: [PATCH] Don't cache CSL.Engine for integration --- chrome/content/zotero/xpcom/integration.js | 5 ++++- chrome/content/zotero/xpcom/style.js | 20 +++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 72d198ed88..5a62322243 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -1927,7 +1927,10 @@ Zotero.Integration.Session.prototype.setData = async function (data, resetStyle) if (this.style && this.style.free) { this.style.free(); } - this.style = getStyle.getCiteProc(data.style.locale, this.outputFormat, data.prefs.automaticJournalAbbreviations); + this.style = getStyle.getCiteProc(data.style.locale, this.outputFormat, { + automaticJournalAbbreviations: data.prefs.automaticJournalAbbreviations, + noCache: true, + }); this.styleClass = getStyle.class; // We're changing the citeproc instance, so we'll have to reinsert all citations into the registry this.rebuildCiteprocState = true; diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js index a76c41f2d4..ff6ed94933 100644 --- a/chrome/content/zotero/xpcom/style.js +++ b/chrome/content/zotero/xpcom/style.js @@ -700,9 +700,23 @@ Zotero.Style = function (style, path) { * Get a citeproc-js CSL.Engine instance * @param {String} locale Locale code * @param {String} [format] Output format one of [rtf, html, text] - * @param {Boolean} [automaticJournalAbbreviations] Whether to automatically abbreviate titles + * @param {GetCiteProcOptions | boolean} [options] If passed as a boolean, sets automaticJournalAbbreviations + * @param {boolean} [options.automaticJournalAbbreviations] Abbreviate publication titles automatically + * @param {boolean} [options.noCache] Don't read or write the CSL.Engine cache. This should only be used in code that + * relies on the CSL.Engine's internal state to persist properties between citation/bibliography generations. + * Callers that will only use the CSL.Engine instance once should always take advantage of the cache. + * + * @typedef {{ + * automaticJournalAbbreviations?: boolean; + * noCache?: boolean; + * }} GetCiteProcOptions */ -Zotero.Style.prototype.getCiteProc = function (locale, format, automaticJournalAbbreviations) { +Zotero.Style.prototype.getCiteProc = function (locale, format, options = {}) { + if (typeof options === 'boolean') { + options = { automaticJournalAbbreviations: options }; + } + let { automaticJournalAbbreviations, noCache } = options; + locale = locale || Zotero.locale || 'en-US'; format = format || 'text'; automaticJournalAbbreviations = !!automaticJournalAbbreviations; @@ -711,7 +725,7 @@ Zotero.Style.prototype.getCiteProc = function (locale, format, automaticJournalA // We can cache the Engine instance if we aren't using citeproc-rs // and this is an installed style - let cacheKey = !useCiteprocRs && this.path + let cacheKey = !noCache && !useCiteprocRs && this.path ? JSON.stringify({ locale, format, automaticJournalAbbreviations }) : null; if (cacheKey && this._cachedEngines.has(cacheKey)) {