-
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 16 and Enzyme 3 migration #1885
Conversation
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.
make sure to check out the lockfile
import { CSSTransition } from "react-transition-group"; | ||
import { IOverlayProps } from "./overlay"; | ||
|
||
export function OverlayTransition< |
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.
this is no longer used; will remove
transitionLeaveTimeout={transitionDuration} | ||
transitionName={transitionName} | ||
> | ||
<TransitionGroup appear={true}> |
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.
@@ -38,8 +37,7 @@ export interface IButtonGroupProps extends IProps, React.HTMLProps<HTMLDivElemen | |||
|
|||
// this component is simple enough that tests would be purely tautological. | |||
/* istanbul ignore next */ | |||
@PureRender | |||
export class ButtonGroup extends React.Component<IButtonGroupProps, {}> { | |||
export class ButtonGroup extends React.PureComponent<IButtonGroupProps, {}> { |
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.
we should be able to drop these empty {}
state types, as the React types now provide a default: interface Component<P = {}, S = {}>
.
though it's fine to not do this now, or ever.
@@ -31,8 +30,7 @@ export interface IIconProps extends IIntentProps, IProps { | |||
iconSize?: 16 | 20 | "inherit"; | |||
} | |||
|
|||
@PureRender | |||
export class Icon extends React.Component<IIconProps & React.HTMLAttributes<HTMLSpanElement>, never> { | |||
export class Icon extends React.PureComponent<IIconProps & React.HTMLAttributes<HTMLSpanElement>, never> { |
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.
remove never
, or make it {}
like all the others
onMouseDown={this.handleBackdropMouseDown} | ||
tabIndex={this.props.canOutsideClickClose ? 0 : null} | ||
/> | ||
<CSSTransition classNames={transitionName} timeout={transitionDuration}> |
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.
classNames
😱
should we do this??
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.
that's their API. are you asking if we should do this for our own props? I don't think there's anything wrong with the current names, so would prefer to keep them
constructor(props: IPortalProps, context: IPortalContext) { | ||
super(props, context); | ||
this.targetElement = document.createElement("div"); | ||
this.targetElement.classList.add(Classes.PORTAL); |
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.
why move to constructor instead of didMount?
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.
it happens sooner this way. also this is how the API example was set up
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.
oh also I need it to be there by the time render()
is called, which is not true of componentDidMount
Address follow up comments on #1898Preview: documentation | landing | table |
Remove extraneous core karma test configPreview: documentation | landing | table |
Some regressions I noticed (which can be addressed in follow-up PRs):
|
Filed #1901 to address those later ^ |
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.
Questions. Otherwise good to go
"src/accessibility/*", | ||
"src/common/abstractComponent*", | ||
// deprecated components | ||
"src/components/popover/*", |
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.
are these actually deprecated if they're being replaced by labs components?
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.
we'll need to remember to remove this line when @cmslewis's Popover2 -> Popover change goes in.
); | ||
} | ||
|
||
public componentDidMount() { |
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.
it looks like componentDidMount
is maintained, but componentDidUpdate
was removed which used an unstable method. Is this functionality still captured?
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.
yeah so now that we're actually returning something from render
instead of null
all the time, the React tree works as expected. there's a unit test for the context-preserving functionality (it("respects blueprintPortalClassName on context"
)
@@ -2,4 +2,11 @@ | |||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | |||
*/ | |||
|
|||
import "es6-shim"; |
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.
wasn't this supposed to be removed?
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.
(though it's just test code code, so... yolo)
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.
no, you explicitly need to bring it in to support React 16. We're definitely not removing es6-shim from the page runtime; we are pushing the responsibility down to consumers of the library (e.g. the test environment, table-dev-app, docs-app, our other apps, etc.)
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.
oh i see
packages/table/src/table.tsx
Outdated
@@ -492,7 +492,7 @@ export class Table extends AbstractComponent<ITableProps, ITableState> { | |||
// time. it serves as a signal that we can switch to batch rendering. | |||
private didCompletelyMount = false; | |||
|
|||
public constructor(props: ITableProps, context?: any) { | |||
public constructor(props: ITableProps & { children: React.ReactNode }, context?: any) { |
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.
ITableProps
already has a definition for children
, shouldn't these match?
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.
yeah good catch. will fix
packages/table/src/table.tsx
Outdated
@@ -664,7 +664,8 @@ export class Table extends AbstractComponent<ITableProps, ITableState> { | |||
); | |||
} | |||
|
|||
public componentWillReceiveProps(nextProps: ITableProps) { | |||
public componentWillReceiveProps(nextProps: ITableProps & { children: React.ReactNode }) { |
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.
^ same
Remove extra props interface in table implPreview: documentation | landing | table |
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.
Requesting changes for the test:karma:debug
thing in particular.
public componentWillUnmount() { | ||
ReactDOM.unmountComponentAtNode(this.targetElement); |
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.
Why don't we need this anymore?
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.
React cleans up itself when you actually return things in render
@@ -39,8 +38,7 @@ export interface ITab2Props extends IProps { | |||
title?: string | JSX.Element; | |||
} | |||
|
|||
@PureRender | |||
export class Tab2 extends React.Component<ITab2Props, {}> { | |||
export class Tab2 extends React.PureComponent<ITab2Props, {}> { |
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.
@giladgray FYI: this edit. (You moved these files in #1900.)
@@ -22,7 +22,7 @@ import { | |||
describe("<CollapsibleList>", () => { | |||
it("adds className to itself", () => { | |||
const list = renderCollapsibleList(3, { className: "winner" }); | |||
assert.lengthOf(list.find(".winner"), 1); | |||
assert.isNotEmpty(list.find(".winner")); |
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.
Hmm, this check isn't equivalent. Was this suffering from Enzyme 3's .hostNodes()
issue (enzymejs/enzyme#1174)? Seems like the fix for too many elements here is:
assert.lengthOf(list.find(".winner").hostNodes(), 1);
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.
Yeah but is that really a more meaningful / useful test? IMO this is another tautology and I would rather have a auto-generated test suite for spreading props / classNames rather than including one of these test cases at the start of every component test suite
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.
ok I can switch to hostNodes
@@ -15,7 +15,7 @@ describe("<Text>", () => { | |||
const textContent = "textContent"; | |||
const className = "bp-test-class"; | |||
const wrapper = mount(<Text className={className}>{textContent}</Text>); | |||
const element = wrapper.find(`.${className}`); | |||
const element = wrapper.find(`div.${className}`); |
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.
wrapper.find(`.${className}`).hostNodes()
is clearer
@@ -130,10 +128,11 @@ describe("Toaster", () => { | |||
|
|||
it("focuses on newly created toast", done => { | |||
toaster.show({ message: "focus on me" }); | |||
// small explicity timeout reduces flakiness of these tests |
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.
explicit
ly
packages/labs/package.json
Outdated
@@ -24,6 +24,7 @@ | |||
"test": "npm-run-all -s test:pre -p test:karma", | |||
"test:pre": "tsc -p ./test", | |||
"test:karma": "karma start", | |||
"test:karma:debug": "karma start --browsers=Chrome --single-run=false --reporters=mocha --debug", |
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.
Same
packages/select/package.json
Outdated
@@ -24,26 +24,28 @@ | |||
"test": "npm-run-all -s compile:cjs test:pre -p test:karma test:iso", | |||
"test:pre": "tsc -p ./test", | |||
"test:karma": "karma start", | |||
"test:karma:debug": "karma start --browsers=Chrome --single-run=false --reporters=mocha --debug", |
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.
Same
@@ -73,7 +73,7 @@ describe("Suggest", () => { | |||
|
|||
it("scrolls active item into view when popover opens", () => { | |||
const wrapper = suggest(); | |||
const queryList = (wrapper.getNode() as any).queryList; // private ref | |||
const queryList = ((wrapper.instance() as Suggest<Film>) as any).queryList; // private ref |
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 does double-casting do for us?
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.
just helps clarify intent to developers
packages/table/package.json
Outdated
@@ -24,27 +24,29 @@ | |||
"test": "npm-run-all -s compile:cjs test:pre -p test:karma test:iso", | |||
"test:pre": "tsc -p ./test", | |||
"test:karma": "karma start", | |||
"test:karma:debug": "karma start --browsers=Chrome --single-run=false --reporters=mocha --debug", |
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.
Same
packages/table/src/table.tsx
Outdated
@@ -492,7 +492,7 @@ export class Table extends AbstractComponent<ITableProps, ITableState> { | |||
// time. it serves as a signal that we can switch to batch rendering. | |||
private didCompletelyMount = false; | |||
|
|||
public constructor(props: ITableProps, context?: any) { | |||
public constructor(props: ITableProps & { children: React.ReactNode }, context?: any) { |
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.
Worth making a new props interface in core/.../props.ts
? This is used in a few places.
e.g.
export interface IChildrenProps {
children: React.ReactNode;
}
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.
no, I removed it
Address CR feedback on testsPreview: documentation | landing | table |
@hysoftwareeng this will be in our upcoming 2.0 release, but the installation instructions do not change: react is still a |
When will a release be cut for 2.0? It's not possible to upgrade to React 16 if blueprintjs is a dependency. Thanks! |
What are the specific errors you run into? React 16 is supported as a peer dependency: #1660 |
I have the following error when trying to upgrade to React 16:
But where does pure-render-decorator/react-addons-css-transition-group come from? the pure-render-decorator is a requirement for these two packages. and I get this warning when I try to move to react-transition-group
|
Those warnings can be safely ignored. See #866 (comment). Anyway, I just released the first beta of blueprint 2.0.0, you can try it out for react 16 support. Release notes coming soon. |
Thanks |
@adidahiya not sure I follow. When I upgrade to React
|
@skovy Since these are peer dependencies, no, you don't need to end up with two versions of React in your bundle. Warnings aside, does this cause a problem at runtime in your application when you try to use React 16.2.0? Also, I suggest upgrading react-day-picker to a version that allows React 16 as a peer dependency: https://github.com/gpbl/react-day-picker/blob/3156e3de1664caa15cf12cfd0fdd96350874e8c5/package.json#L55 |
@adidahiya got it, thanks for the insight and I appreciate the help! 👍 |
@adidahiya I opened a PR to upgrade |
Fixes #1051
Fixes #144
Fixes #866 (for real)
Fixes #1860
Fixes #1680
Changes in this PR
react
andreact-dom
to v16es6-shim
in all tests to ensure compatibilityreact-addons-css-transition-group
withreact-transition-group
pure-render-decorator
usage withextends React.PureComponent
AbstractComponent
into impureAbstractComponent
and pureAbstractPureComponent
classesenzyme
to v3 and installenzyme-adapter-react-16
<Portal>
: ReplaceReactDOM._unstableRenderSubtreeToContainer
withReactDOM.createPortal