From b3e873782944ba49db05ee289ac241b8b34021e1 Mon Sep 17 00:00:00 2001 From: Adam Wight Date: Sun, 20 Oct 2024 10:44:03 +0200 Subject: [PATCH] Fix regression to auto-save Cite's MWDocumentReferences included a Document, which caused auto-save serialization to fail silently on the cyclical reference. This patch moves the caching to per-instance scope, which was the better choice to begin with. The document refs are recalculated after each change anyway, and caching is only necessary to work around an awkward control flow in which each ReferenceNode is responsible for its footnote number. Bug: T377484 Change-Id: Iebe4befd603fe07d9da2a5bb6126228ec4d5dfea --- modules/ve-cite/ve.dm.MWDocumentReferences.js | 6 +++--- .../ve-cite/ve.ui.MWUseExistingReferenceCommand.test.js | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/ve-cite/ve.dm.MWDocumentReferences.js b/modules/ve-cite/ve.dm.MWDocumentReferences.js index 72b9477cc..a74a7d649 100644 --- a/modules/ve-cite/ve.dm.MWDocumentReferences.js +++ b/modules/ve-cite/ve.dm.MWDocumentReferences.js @@ -47,15 +47,15 @@ OO.mixinClass( ve.dm.MWDocumentReferences, OO.EventEmitter ); */ ve.dm.MWDocumentReferences.static.refsForDoc = function ( doc ) { let docRefs; + // Only use cache if we're working with the full document. if ( !doc.getOriginalDocument() ) { - // Only use cache if we're working with the full document. - docRefs = doc.getStorage( 'document-references-store' ); + docRefs = doc.extCiteDocumentReferences; } if ( docRefs === undefined ) { docRefs = new ve.dm.MWDocumentReferences( doc ); } if ( !doc.getOriginalDocument() ) { - doc.setStorage( 'document-references-store', docRefs ); + doc.extCiteDocumentReferences = docRefs; } return docRefs; }; diff --git a/tests/qunit/ve-cite/ve.ui.MWUseExistingReferenceCommand.test.js b/tests/qunit/ve-cite/ve.ui.MWUseExistingReferenceCommand.test.js index 3c2c4f10a..aae8c1f51 100644 --- a/tests/qunit/ve-cite/ve.ui.MWUseExistingReferenceCommand.test.js +++ b/tests/qunit/ve-cite/ve.ui.MWUseExistingReferenceCommand.test.js @@ -9,9 +9,8 @@ function getFragmentMock( hasRefs ) { return { getDocument: () => ( { - getOriginalDocument: () => undefined, - getStorage: () => docRefsMock, - setStorage: () => undefined + extCiteDocumentReferences: docRefsMock, + getOriginalDocument: () => undefined } ), getSelection: () => ( { getName: () => 'linear'