From 9683fd9aeca0c5d17dc23bc07005bbbf76bd96b5 Mon Sep 17 00:00:00 2001 From: Yann Flory Date: Wed, 13 Apr 2016 16:46:31 +0200 Subject: [PATCH] Always serialize the DOM in one way. --- www/pad/main.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/www/pad/main.js b/www/pad/main.js index 1465681ae..5d2b168d7 100644 --- a/www/pad/main.js +++ b/www/pad/main.js @@ -44,6 +44,16 @@ define([ return true; }; + /* catch `type="_moz"` before it goes over the wire */ + var brFilter = function (hj) { + if (hj[1].type === '_moz') { hj[1].type = undefined; } + return hj; + }; + + var stringifyDOM = function (dom) { + return JSON.stringify(Hyperjson.fromDOM(dom, isNotMagicLine, brFilter)); + }; + var andThen = function (Ckeditor) { /* This is turned off because we prefer that the channel name be chosen by the server, not generated by the client. @@ -189,7 +199,7 @@ define([ var realtimeOptions = { // provide initialstate... - initialState: JSON.stringify(Hyperjson.fromDOM(inner, isNotMagicLine)), + initialState: stringifyDOM(inner) || '{}', // the websocket URL websocketURL: Config.websocketURL, @@ -241,8 +251,7 @@ define([ // Build a new stringified Chainpad hyperjson without metadata to compare with the one build from the dom shjson = JSON.stringify(hjson); - var hjson2 = Hyperjson.fromDOM(inner); - var shjson2 = JSON.stringify(hjson2); + var shjson2 = stringifyDOM(inner); if (shjson2 !== shjson) { console.error("shjson2 !== shjson"); module.realtimeInput.patchText(shjson2); @@ -283,12 +292,6 @@ define([ var rti = module.realtimeInput = realtimeInput.start(realtimeOptions); - /* catch `type="_moz"` before it goes over the wire */ - var brFilter = function (hj) { - if (hj[1].type === '_moz') { hj[1].type = undefined; } - return hj; - }; - /* It's incredibly important that you assign 'rti.onLocal' It's used inside of realtimeInput to make sure that all changes make it into chainpad.