Skip to content

Commit

Permalink
prevent mutation on vdom elements
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk committed Sep 26, 2017
1 parent bdd0966 commit b3974b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 10 additions & 2 deletions notebook/static/notebook/js/object-to-preact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions notebook/static/notebook/js/outputarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

define([
'jquery',
'underscore',
'base/js/utils',
'base/js/i18n',
'base/js/security',
Expand All @@ -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";

/**
Expand Down Expand Up @@ -711,7 +710,7 @@ define([
);

element.append(toinsert);
preact.render(otp.objectToPreactElement(_.clone(vdom)), toinsert[0]);
preact.render(otp.objectToPreactElement(vdom), toinsert[0]);

return toinsert;
};
Expand Down

0 comments on commit b3974b9

Please sign in to comment.