ve.dm.MWReferenceNode contains a comparison of element linear data done using a simple object reference equality check (===). In debug mode where objects are frozen with ve.deepFreeze - this check always returns false and breaks toDomElements.
The first attempt to fix this resulted in T296044.
Testing
- Open VE in debug mode (?veaction=edit&debug=true)
- Create a basic reference with content (e.g. <ref>Foo</ref>)
- Inspect the wikitext produced (either by: switch to source mode, showing wikitext changes, or saving)
- Observed: The reference is now empty: <ref />
- Expected: The reference contents is preserved