diff --git a/lib/assets/javascripts/react_ujs.js b/lib/assets/javascripts/react_ujs.js index dbffafa7b..d675aace3 100644 --- a/lib/assets/javascripts/react_ujs.js +++ b/lib/assets/javascripts/react_ujs.js @@ -6,6 +6,10 @@ // jQuery is optional. Use it to support legacy browsers. var $ = (typeof jQuery !== 'undefined') && jQuery; + // Maps DOM nodes to booleans specifying whether or not those + // nodes already have a component mounted in them + var mounted = {}; + var findReactDOMNodes = function() { var SELECTOR = '[' + CLASS_NAME_ATTR + ']'; if ($) { @@ -25,7 +29,11 @@ var constructor = window[className] || eval.call(window, className); var propsJson = node.getAttribute(PROPS_ATTR); var props = propsJson && JSON.parse(propsJson); - React.renderComponent(constructor(props), node); + + if (!mounted[node]) { + React.renderComponent(constructor(props), node); + mounted[node] = true; + } } }; @@ -33,6 +41,7 @@ var nodes = findReactDOMNodes(); for (var i = 0; i < nodes.length; ++i) { React.unmountComponentAtNode(nodes[i]); + delete mounted[node]; } };