-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
📦 React 15 support #2426
📦 React 15 support #2426
Changes from 20 commits
0525701
0bd0100
4ae6396
a1d4e08
85e984f
05ee82c
3b31c6f
2c2e6ee
aae2809
8e57b13
8128808
cf11323
d69d9b6
a28fb0c
001b89d
2e78042
4862ced
abae6de
e9688cd
38579eb
9068fea
ab8d1f4
f03de65
d844b0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2018 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the terms of the LICENSE file distributed with this project. | ||
*/ | ||
|
||
import { ReactWrapper } from "enzyme"; | ||
import { Portal } from "../src"; | ||
|
||
export function findInPortal(overlay: ReactWrapper, selector: string) { | ||
// React 16: createPortal preserves React tree so simple find works. | ||
const element = overlay.find(Portal).find(selector); | ||
if (element.exists()) { | ||
return element; | ||
} | ||
|
||
// React 15: unstable_renderSubtree does not preserve tree so we must create new wrapper. | ||
const portal = overlay.find(Portal).instance(); | ||
const portalChildren = new ReactWrapper(portal.props.children as JSX.Element[]); | ||
if (portalChildren.is(selector)) { | ||
return portalChildren; | ||
} | ||
return portalChildren.find(selector); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,14 @@ | |
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
import "./polyfill"; | ||
// Note: using CommonJS syntax here so this can be used in the isomorphic tests, which must run in a server environment. | ||
require("./polyfill"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is it necessary to switch to commonjs for this test code? shouldn't the node version that runs it support es6 modules? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. necessary because isotest uses this now and that suite explicitly runs in a node environment (for server-side rendering). added code comment. |
||
|
||
import * as Enzyme from "enzyme"; | ||
import * as Adapter from "enzyme-adapter-react-16"; | ||
const Enzyme = require("enzyme"); | ||
// test against React 15 with REACT=15 env variable. | ||
const Adapter = require(`enzyme-adapter-react-${process.env.REACT || 16}`); | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
// tslint:disable-next-line:no-console | ||
console.info(`Enzyme configured with \x1b[35m${Adapter.name}\x1b[0m`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you want to use
React.createContext()
or some other new React feature in the future? Supporting both versions might seem like a few hundred LOC right now, but it could end up being pretty limiting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree, it is quite limiting, but it's the quickest path to adoption.
shim/ponyfill packages are available, such as create-react-context, which is actually used in the latest version of react-popper to support multiple versions. so we could go down that route, like we did with pure-render-decorator.