Skip to content

Commit

Permalink
Fix type error and improve name of portal container flag
Browse files Browse the repository at this point in the history
**NOTE:** I am still looking for a good place to move this flag
assignment to, or a better approach. This does some intermediate fixes.

**what is the change?:**
- fixed flow error by allowing optional flag on a DOMContainer that
  indicates it was used as a portal container.
- renamed the flag to something which makes more sense

**why make this change?:**
- get Flow passing
- make this change make more sense

We are still not sure about adding this flag; a follow-up diff may move
it or take a different approach.

**test plan:**
`yarn test`

**issue:**
#8854
  • Loading branch information
flarnie committed Jul 19, 2017
1 parent e1f3854 commit 3a09245
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/renderers/dom/fiber/ReactDOMFiberEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ findDOMNode._injectFiber(function(fiber: Fiber) {
});

type DOMContainer =
| (Element & {_reactRootContainer: ?Object})
| (Document & {_reactRootContainer: ?Object});
| (Element & {
_reactRootContainer: ?Object,
__reactInternalIsPortalContainer: ?boolean,
})
| (Document & {
_reactRootContainer: ?Object,
__reactInternalIsPortalContainer: ?boolean,
});

type Container = Element | Document;
type Props = {
Expand Down Expand Up @@ -538,7 +544,7 @@ function renderSubtreeIntoContainer(
const hostInstanceParentIsPortal =
hostInstance &&
hostInstance.parentNode &&
hostInstance.parentNode._reactPortalContainer;
hostInstance.parentNode.__reactInternalIsPortalContainer;
if (hostInstance && !hostInstanceParentIsPortal) {
warning(
hostInstance.parentNode === container,
Expand Down
3 changes: 2 additions & 1 deletion src/renderers/shared/fiber/isomorphic/ReactPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ exports.createPortal = function(
implementation: any,
key: ?string = null,
): ReactPortal {
containerInfo._reactPortalContainer = {};
// This flag allows us to check if a node was used with a portal
containerInfo.__reactInternalIsPortalContainer = true;
return {
// This tag allow us to uniquely identify this as a React Portal
$$typeof: REACT_PORTAL_TYPE,
Expand Down

0 comments on commit 3a09245

Please sign in to comment.