Page MenuHomePhabricator

Browser hangs for 1 minute when editing all copies of a sub-ref
Closed, ResolvedPublicBUG REPORT

Description

My test case is relatively straightforward. All I do is to copy paste (with Ctrl+C and Ctrl+V) a sub-reference a few times so I have a few copies I can edit. When I edit the last one, keep the checkbox selected, and click apply, the browser hangs for a full minute.

Screenshot from 2025-11-14 15-53-21.png (873×1 px, 127 KB)

Issue
  • To split up a sub-ref from it's reuses we introduced ve.dm.MWReferenceModel.copySubReference
  • In there we create an empty MWReferenceModel and have a step to copy the Document from the editing to that new model
  • We use ve.dm.Document.cloneWithData to do that, but it seems that this will also copy the original InternalList to the ref's document and when the two are merged the original document grows.

See https://gerrit.wikimedia.org/g/mediawiki/extensions/Cite/+/3d0bd2958735b479be93ffbeecb47c86109e504a/modules/ve-cite/ve.dm.MWReferenceModel.js#81

Event Timeline

Something is duplicated internally and goes up in a logarithmic fashion. The more I play around with my example document (doing trivial things that should be linear) I can see that ve.dm.TreeModifier.static.applyTreeOperations is called with more and more treeOps. After a while there are 10000 in the array, then 20000, 40000, and so on.

The call stack comes from ve.dm.MWReferenceModel.prototype.updateInternalItem.

I wonder if this is a problem of sub-refs or if there's the same happening when editing "normal" refs. I can't see anything particularly special about editing sub-ref reuses vs ref reuses. Both call updateInternalItem to insert the updated document. 🤔

( Apart from my comment above I'm not experiencing that lag locally in neither case )

This appears to be specific to sub-refs. When I try the same with main refs I get totally expected treeOps with e.g. 60 operations.

This appears to be specific to sub-refs. When I try the same with main refs I get totally expected treeOps with e.g. 60 operations.

I still cannot reproduce this, we should sit together :-)

Steps to reproduce:

  • Create a minimal document with e.g. <ref details="p2" name="b">Book</ref>. Nothing else needed.
  • Start VE with &debug=true in the URL.
  • Show the model and enable "Update on changes" if you prefer.
  • Notice that the model contains 2 internalItem for the sub-ref and the main ref, as expected.
  • Now copy and paste the ref by highlighting the footnote number, Ctrl+C and Ctrl+V one or more times.
  • Pick one of the duplicates and edit the sub-ref. Change it and uncheck the "edit all uses" checkbox.
  • Now the model contains way to many internalItem. Multiple copies of the main ref as well as multiple copies of the original sub-ref.

We already boiled the issue down to ve.dm.MWReferenceModel.copySubReference where a cloneWithData is apparently cloning things we don't want to clone at that point in time.

We discussed this in the dev sync, and looked at how to clone with an empty internal list, which solves the issue.

Change #1211085 had a related patch set uploaded (by WMDE-Fisch; author: WMDE-Fisch):

[mediawiki/extensions/Cite@master] Don't copy the InternalList when creating a sub-ref copy

https://gerrit.wikimedia.org/r/1211085

Change #1211085 merged by jenkins-bot:

[mediawiki/extensions/Cite@master] Don't copy the InternalList when creating a sub-ref copy

https://gerrit.wikimedia.org/r/1211085