From f80d84e22e6ff27b43e1535e2b9c8699307c88d1 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Mon, 25 Sep 2017 21:38:52 -0700 Subject: [PATCH] prevent mutation on vdom elements --- notebook/static/notebook/js/object-to-preact.js | 12 ++++++++++-- notebook/static/notebook/js/outputarea.js | 5 ++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/notebook/static/notebook/js/object-to-preact.js b/notebook/static/notebook/js/object-to-preact.js index 05e1b28c41..d3dddcd5db 100644 --- a/notebook/static/notebook/js/object-to-preact.js +++ b/notebook/static/notebook/js/object-to-preact.js @@ -93,8 +93,16 @@ define(function() { } else if (typeof item === "string") { result.push(item); } else if (typeof item === "object") { - const keyedItem = item; - item.key = i; + const keyedItem = { + tagName: item.tagName, + attributes: item.attributes, + children: item.children + }; + if (item.attributes && item.attributes.key) { + keyedItem.key = item.attributes.key; + } else { + keyedItem.key = i; + } result.push(objectToPreactElement(keyedItem)); } else { console.warn("invalid vdom data passed", item); diff --git a/notebook/static/notebook/js/outputarea.js b/notebook/static/notebook/js/outputarea.js index 83702c827f..ed3b819441 100644 --- a/notebook/static/notebook/js/outputarea.js +++ b/notebook/static/notebook/js/outputarea.js @@ -3,7 +3,6 @@ define([ 'jquery', - 'underscore', 'base/js/utils', 'base/js/i18n', 'base/js/security', @@ -12,7 +11,7 @@ define([ 'notebook/js/mathjaxutils', 'notebook/js/object-to-preact', 'components/marked/lib/marked', -], function($, _, utils, i18n, security, keyboard, configmod, mathjaxutils, otp, marked) { +], function($, utils, i18n, security, keyboard, configmod, mathjaxutils, otp, marked) { "use strict"; /** @@ -714,7 +713,7 @@ define([ ); element.append(toinsert); - preact.render(otp.objectToPreactElement(_.clone(vdom)), toinsert[0]); + preact.render(otp.objectToPreactElement(vdom), toinsert[0]); return toinsert; };