Skip to content

Commit f7efe64

Browse files
committed
Ignore portals in DOMRenderer.findHostInstance
**what is the change?:** We want to ignore portals when firing a certain warning. This allows us to get the host instance and ignore portals. Also added a new snapshot recording while fixing things. **why make this change?:** Originally we had added a flag to the DOM node which was used for rendering the portal, and then could notice and ignore children rendered into those nodes. However, it's better to just ignore portals in `DOMRenderer.findHostInstance` because - we will not ignore a non-portal second child with this approach - we meant to ignore portals in this method anyway (according to a 'TODO' comment) - this change only affects the DOM renderer, instead of changing code which is shared with RN and other renderers - we avoid adding unneeded expandos **test plan:** `yarn test` **issue:** facebook#8854
1 parent 2225b98 commit f7efe64

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/renderers/dom/fiber/ReactDOMFiberEntry.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ findDOMNode._injectFiber(function(fiber: Fiber) {
7474

7575
type DOMContainer =
7676
| (Element & {
77-
_reactRootContainer: ?Object,
77+
_reactRootContainer: ?Object
7878
})
7979
| (Document & {
80-
_reactRootContainer: ?Object,
80+
_reactRootContainer: ?Object
8181
});
8282

8383
type Container = Element | Document;
@@ -539,12 +539,7 @@ function renderSubtreeIntoContainer(
539539
const hostInstance = DOMRenderer.findHostInstance(
540540
container._reactRootContainer.current,
541541
);
542-
const hostInstanceParentNode: any =
543-
hostInstance && hostInstance.parentNode;
544-
const hostInstanceParentIsPortal =
545-
hostInstanceParentNode &&
546-
hostInstanceParentNode.__reactInternalIsPortalContainer;
547-
if (hostInstance && !hostInstanceParentIsPortal) {
542+
if (hostInstance) {
548543
warning(
549544
hostInstance.parentNode === container,
550545
'render(...): It looks like the React-rendered content of this ' +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`ReactDOMFiber should warn when replacing a container which was manually updated outside of React 1`] = `""`;

src/renderers/shared/fiber/ReactFiberTreeReflection.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ if (__DEV__) {
2525
}
2626

2727
var {
28-
HostRoot,
28+
ClassComponent,
2929
HostComponent,
30+
HostRoot,
31+
HostPortal,
3032
HostText,
31-
ClassComponent,
3233
} = require('ReactTypeOfWork');
3334

3435
var {NoEffect, Placement} = require('ReactTypeOfSideEffect');
@@ -241,8 +242,7 @@ exports.findCurrentHostFiber = function(parent: Fiber): Fiber | null {
241242
while (true) {
242243
if (node.tag === HostComponent || node.tag === HostText) {
243244
return node;
244-
} else if (node.child) {
245-
// TODO: If we hit a Portal, we're supposed to skip it.
245+
} else if (node.child && node.tag !== HostPortal) {
246246
node.child.return = node;
247247
node = node.child;
248248
continue;

0 commit comments

Comments
 (0)