<p dir="auto">Demonstrated at <a href="http://jsfiddle.net/xnhzvdoa/1/" rel="nofollow">http://jsfiddle.net/xnhzvdoa/1/</a>; open the error console and you should see this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Uncaught Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you're trying to add a ref to a component that doesn't have an owner (that is, was not created inside of another component's `render` method). Try rendering this component inside of a new top-level component which will hold the ref."><pre class="notranslate"><code class="notranslate">Uncaught Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you're trying to add a ref to a component that doesn't have an owner (that is, was not created inside of another component's `render` method). Try rendering this component inside of a new top-level component which will hold the ref.
</code></pre></div>
<hr>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var Bug = React.createClass({
    render: function() {
        var html = React.renderToStaticMarkup(React.DOM.img());
        return React.DOM.div({ ref: 'ref' }, html);
    }
});
Bug = React.createFactory(Bug);

React.render(Bug(), document.body);"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-v">Bug</span> <span class="pl-c1">=</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-en">createClass</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
    <span class="pl-en">render</span>: <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">html</span> <span class="pl-c1">=</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-en">renderToStaticMarkup</span><span class="pl-kos">(</span><span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-c1">DOM</span><span class="pl-kos">.</span><span class="pl-en">img</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">return</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-c1">DOM</span><span class="pl-kos">.</span><span class="pl-en">div</span><span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c1">ref</span>: <span class="pl-s">'ref'</span> <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-s1">html</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-v">Bug</span> <span class="pl-c1">=</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-en">createFactory</span><span class="pl-kos">(</span><span class="pl-v">Bug</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-en">render</span><span class="pl-kos">(</span><span class="pl-v">Bug</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-smi">document</span><span class="pl-kos">.</span><span class="pl-c1">body</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Idea (that I'm pretty sure I saw elsewhere, react-native maybe?)…</p>
<p dir="auto">We should transform our <code class="notranslate">invariant</code> calls to a conditional wrapping the call. We have to check the condition <em>anyway</em> and this would reduce the no-op function calls.</p>
<p dir="auto">In otherwords</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function doSomething(someArg) {
  invariant(someArg !== undefined, 'hey doofus, don't pass undefined');
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-s1">someArg</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-en">invariant</span><span class="pl-kos">(</span><span class="pl-s1">someArg</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span><span class="pl-kos">,</span> <span class="pl-s">'hey doofus, don'</span><span class="pl-s1">t</span> <span class="pl-s1">pass</span> <span class="pl-c1">undefined</span>'<span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">becomes</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function doSomething(someArg) {
  if (!(someArg !== undefined)) {
    invariant(false);
  }
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-s1">someArg</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">someArg</span> <span class="pl-c1">!==</span> <span class="pl-c1">undefined</span><span class="pl-kos">)</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">invariant</span><span class="pl-kos">(</span><span class="pl-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Hell, we could replace the <code class="notranslate">invariant(false)</code> with <code class="notranslate">throw new Error('whatevs')</code> and get rid of the function call entirely, though it really doesn't matter much since we're going to throw (plus we'd duplicate the default string).</p>
<p dir="auto">This might end up be a meaningless optimization…</p>