Steps to replicate the issue
- Create a page with the following minimal content on a wiki using the reflist-template (e.g. enwiki):
Test.<ref>Reference 1</ref>
== References ==
{{Reflist}}- Edit the page in VisualEditor and add another reference.
What happens?
- The newly added reference doesn't appear in the reference list as long as you're editing (it shows in the reference pop-up).
- The reference is displayed after saving the page – and also when switching to wikitext (and back to VE) in the same edit session.
What should have happened instead?
- Always show newly added references in the reference list while editing in VE.
Other information
- Reported in https://en.wikipedia.org/wiki/Wikipedia:Village_pump_(technical)#Visual_editor_not_updating_reflist_on_new_%3Cref%3E
- Pages using <references /> are not affected.
- Initial investigation by @WMDE-Fisch indicates that the issue might be related to recent changes to Parsoid.
Background
The Cite VisualEditor implementation tries to detect a references tag that's transcluded from a template. The code for that was mainly added and maintained for {{reflist}}[1]. The detection assumes a certain structure in the Parsoid output to work. It seems that two changes broke that detection recently and that's why the support for {{reflist}} on English Wikipedia degraded.
This is a minimal version of {{reflist}} to reproduce the issue:
<templatestyles src="Reflist/styles.css" /><div>{{#tag:references}}</div>You also need to create the Reflist/styles.css file so that TemplateStyles does not throw errors.
You can also use this import:
Issue
The Parsoid output VE expects looks something like
<style data-mw-deduplicate="TemplateStyles:r2129" typeof="mw:Extension/templatestyles mw:Transclusion" about="#mwt2"
data-mw="{"name":"templatestyles","attrs":{"src":"Reflist/styles.css"},"parts":[{"template":{"target":{"wt":"reflist","href":"./Template:Reflist"},"params":{},"i":0}}]}"
id="mwBw"></style>
<div about="#mwt2" id="mwCA">
<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt4"
data-mw="{"name":"references","attrs":{}}" id="mwCQ">If the template maintainer adds a newline after the <templatestyles> tag this is already messing with how Parsoid parses that and VE's detection stops working. A change[2] on English Wikipedia already messed with that.
But furthermore a recent Parsoid change also "broke" the detection because it changed the output of the above template transclusion. So even with the "correct" template format it would not work anymore.
See the difference in the output with Version 0.23.0-a29
<div about="#mwt2" typeof="mw:Transclusion"
data-mw="{"parts":[{"template":{"target":{"wt":"reflist","href":"./Template:Reflist"},"params":{},"i":0}}]}"
id="mwBw">
<style data-mw-deduplicate="TemplateStyles:r2129" typeof="mw:Extension/templatestyles" about="#mwt3"
data-mw="{"name":"templatestyles","attrs":{"src":"Reflist/styles.css"}}"></style>
<div class="mw-references-wrap" typeof="mw:Extension/references" about="#mwt4"
data-mw="{"name":"references","attrs":{}}" id="mwCA">Solution
TBD I guess we need to clearify what to expect from Parsoid and either improve the VisualEditor detection. Or both :-).
[1] https://gerrit.wikimedia.org/g/mediawiki/extensions/Cite/+/6388c77976b1c668838aed42468737733e1c03df/modules/ve-cite/ve.dm.MWReferencesListNode.js#63
[2] https://en.wikipedia.org/w/index.php?title=Template:Reflist&diff=prev&oldid=1327269895
