Page MenuHomePhabricator

VisualEditor: JSON.stringify won't work if data contains DOM elements
Closed, ResolvedPublic


Steps to reproduce problem:

  1. Edit in VisualEditor
  2. Add some text
  3. "Review and save"
  4. "Something is wrong"
  5. "Report problem"

Expected behaviour:
Make an http request somewhere and report back in the UI.

Actual behaviour:
No http request is made and UI is unresponsive.


Uncaught TypeError: Converting circular structure to JSON

mw.Target.prototype.reportProblem = function(message) {
var ...., report = { title: .., oldid: .., .. };
$.post(mw.config.get('wgVisualEditorConfig').reportProblemURL, {'data': JSON.stringify(report)}, function() {


var objs = [];
JSON.stringify(a, function (k, v) {

var i;
if (v === Object(v)) {
  i = objs.indexOf(v);
  if (i !== -1) {
    console.log('dupe at #' + i, v);
return v;

dupe at #66
<p data-parsoid=​"{"dsr":​[0,139,0,0]​}​">​
"The "
<b data-parsoid=​"{"tsr":​[4,7]​,"dsr":​[4,24,3,3]​}​">​commit message​</b>​
" play an important role in revision control systems. They are the first thing other people will see of your commit."

Version: unspecified
Severity: critical



Event Timeline

bzimport raised the priority of this task from to Unbreak Now!.Nov 22 2014, 1:28 AM
bzimport set Reference to bz47948.
Krinkle created this task.May 1 2013, 6:51 PM

@Ed: I suspect the circular reference is coming from inside the data model. Can you look into this?

See, method #reportProblem.

This is caused by the linear data now contain DOM elements in alien nodes (and other nodes that store original HTML). We will need to pre-process the data before serialising. We already do this in the unit tests so shouldn't be too difficult.

Related URL: (Gerrit Change Id807ccc6ff31d063be815ed4988cb35684adb76a)

Ah, because native DOM element objects have all kinds of "convenience" pointers like "firstChild", "children", "nextSibling", "paretNode", "ownerDocument", which all have the same as well, so its like a circular reference nightmare.

Fixed in master.