Wrap all top-level components for consistency
Ben Alpert committed
Jun 15, 2015 at 18:04 UTC
643651b8e5f91de4e59580b46330a1aba4e66100
1 file changed
+30
-6
src/renderers/dom/client/ReactMount.js
+30
-6
@@ -274,7 +274,11 @@ function mountComponentIntoNode(
274
var markup = ReactReconciler.mountComponent(
275
componentInstance, rootID, transaction, context
276
);
277
- componentInstance._isTopLevel = true;
277
+ if (typeof componentInstance._renderedComponent._currentElement.type ===
278
+ 'function') {
279
+ // hax
280
+ componentInstance._renderedComponent._isTopLevel = true;
281
+ }
282
ReactMount._mountImageIntoNode(markup, container, shouldReuseMarkup);
283
}
284
@@ -328,6 +332,17 @@ function unmountComponentFromNode(instance, container) {
332
}
333
}
334
335
+/**
336
+ * Temporary (?) hack so that we can store all top-level pending updates on
337
+ * composites instead of having to worry about different types of components
338
+ * here.
339
+ */
340
+var TopLevelWrapper = function() {};
341
+TopLevelWrapper.prototype.render = function() {
342
+ // this.props is actually a ReactElement
343
+ return this.props;
344
+};
345
+
346
/**
347
* Mounting is the process of initializing a React component by creating its
348
* representative DOM elements and inserting them into a supplied `container`.
@@ -522,17 +537,26 @@ var ReactMount = {
537
'for your app.'
538
);
539
540
+ var nextWrappedElement = new ReactElement(
541
+ TopLevelWrapper,
542
+ null,
543
+ null,
544
+ null,
545
+ nextElement
546
+ );
547
+
548
var prevComponent = instancesByReactRootID[getReactRootID(container)];
549
550
if (prevComponent) {
528
- var prevElement = prevComponent._currentElement;
551
+ var prevWrappedElement = prevComponent._currentElement;
552
+ var prevElement = prevWrappedElement.props;
553
if (shouldUpdateReactComponent(prevElement, nextElement)) {
554
return ReactMount._updateRootComponent(
555
prevComponent,
532
- nextElement,
556
+ nextWrappedElement,
557
container,
558
callback
535
- ).getPublicInstance();
559
+ )._renderedComponent.getPublicInstance();
560
} else {
561
ReactMount.unmountComponentAtNode(container);
562
}
@@ -563,7 +587,7 @@ var ReactMount = {
587
588
var shouldReuseMarkup = containerHasReactMarkup && !prevComponent;
589
var component = ReactMount._renderNewRootComponent(
566
- nextElement,
590
+ nextWrappedElement,
591
container,
592
shouldReuseMarkup,
593
parentComponent != null ?
@@ -571,7 +595,7 @@ var ReactMount = {
595
parentComponent._reactInternalInstance._context
596
) :
597
emptyObject
574
- ).getPublicInstance();
598
+ )._renderedComponent.getPublicInstance();
599
if (callback) {
600
callback.call(component);
601
}