Skip to content

Commit 588464d

Browse files
fix next.js
1 parent d416081 commit 588464d

File tree

13 files changed

+278
-37
lines changed

13 files changed

+278
-37
lines changed

.babelrc

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"docs-development": {
2626
"presets": ["next/babel"],
2727
"plugins": [
28-
"preval",
28+
"./scripts/material-ui-babel-preval",
2929
[
3030
"module-resolver",
3131
{
@@ -45,7 +45,7 @@
4545
"docs-production": {
4646
"presets": ["next/babel"],
4747
"plugins": [
48-
"preval",
48+
"./scripts/material-ui-babel-preval",
4949
[
5050
"module-resolver",
5151
{
@@ -62,6 +62,7 @@
6262
"transform-react-constant-elements",
6363
"transform-dev-warning",
6464
"@babel/transform-runtime",
65+
"@babel/plugin-transform-flow-strip-types",
6566
["react-remove-properties", { "properties": ["data-mui-test"] }],
6667
["transform-react-remove-prop-types", { "mode": "remove" }]
6768
]
@@ -112,5 +113,6 @@
112113
]
113114
]
114115
}
115-
}
116+
},
117+
"ignore": ["scripts/material-ui-babel-preset.js", "scripts/*.js"]
116118
}

.yarnrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
network-timeout 150000

docs/src/modules/components/Link.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4+
import compose from 'recompose/compose';
5+
import { withRouter } from 'next/router';
46
import NextLink from 'next/link';
57
import { withStyles } from 'material-ui/styles';
68

@@ -50,17 +52,18 @@ OnClick.propTypes = {
5052
onCustomClick: PropTypes.func,
5153
};
5254

53-
function Link(props, context) {
55+
function Link(props) {
5456
const {
5557
activeClassName,
5658
children: childrenProp,
57-
component: ComponentProp,
5859
classes,
5960
className: classNameProp,
60-
variant,
61+
component: ComponentProp,
6162
href,
6263
onClick,
6364
prefetch,
65+
router,
66+
variant,
6467
...other
6568
} = props;
6669

@@ -82,12 +85,11 @@ function Link(props, context) {
8285
prefetch,
8386
passHref: true,
8487
};
85-
const active = context.url.pathname === href;
8688
children = (
8789
<OnClick
8890
component="a"
8991
className={classNames(className, {
90-
[activeClassName]: active && activeClassName,
92+
[activeClassName]: router.pathname === href && activeClassName,
9193
})}
9294
onCustomClick={onClick}
9395
{...other}
@@ -111,12 +113,6 @@ Link.defaultProps = {
111113
activeClassName: 'active',
112114
};
113115

114-
Link.contextTypes = {
115-
url: PropTypes.shape({
116-
pathname: PropTypes.string.isRequired,
117-
}).isRequired,
118-
};
119-
120116
Link.propTypes = {
121117
activeClassName: PropTypes.string,
122118
children: PropTypes.node.isRequired,
@@ -126,7 +122,10 @@ Link.propTypes = {
126122
href: PropTypes.string,
127123
onClick: PropTypes.func,
128124
prefetch: PropTypes.bool,
125+
router: PropTypes.shape({
126+
pathname: PropTypes.string.isRequired,
127+
}).isRequired,
129128
variant: PropTypes.oneOf(['default', 'primary', 'secondary', 'button']),
130129
};
131130

132-
export default withStyles(styles)(Link);
131+
export default compose(withRouter, withStyles(styles))(Link);

docs/src/modules/components/withRoot.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import find from 'lodash/find';
4+
import { withRouter } from 'next/router';
45
import { Provider } from 'react-redux';
56
import AppWrapper from 'docs/src/modules/components/AppWrapper';
67
import initRedux from 'docs/src/modules/redux/initRedux';
@@ -229,23 +230,23 @@ const pages = [
229230
},
230231
];
231232

232-
function findActivePage(currentPages, url) {
233+
function findActivePage(currentPages, router) {
233234
const activePage = find(currentPages, page => {
234235
if (page.children) {
235-
return url.pathname.indexOf(page.pathname) === 0;
236+
return router.pathname.indexOf(page.pathname) === 0;
236237
}
237238

238239
// Should be an exact match if no children
239-
return url.pathname === page.pathname;
240+
return router.pathname === page.pathname;
240241
});
241242

242243
if (!activePage) {
243244
return null;
244245
}
245246

246247
// We need to drill down
247-
if (activePage.pathname !== url.pathname) {
248-
return findActivePage(activePage.children, url);
248+
if (activePage.pathname !== router.pathname) {
249+
return findActivePage(activePage.children, router);
249250
}
250251

251252
return activePage;
@@ -260,19 +261,18 @@ function withRoot(Component) {
260261
}
261262

262263
getChildContext() {
263-
const url = this.props.url;
264+
const { router } = this.props;
264265

265-
let pathname = url.pathname;
266+
let pathname = router.pathname;
266267
if (pathname !== '/') {
267268
// The leading / is only added to support static hosting (resolve /index.html).
268269
// We remove it to normalize the pathname.
269270
pathname = pathname.replace(/\/$/, '');
270271
}
271272

272273
return {
273-
url,
274274
pages,
275-
activePage: findActivePage(pages, { ...url, pathname }),
275+
activePage: findActivePage(pages, { ...router, pathname }),
276276
};
277277
}
278278

@@ -296,11 +296,10 @@ function withRoot(Component) {
296296
WithRoot.propTypes = {
297297
pageContext: PropTypes.object,
298298
reduxServerState: PropTypes.object,
299-
url: PropTypes.object,
299+
router: PropTypes.object.isRequired,
300300
};
301301

302302
WithRoot.childContextTypes = {
303-
url: PropTypes.object,
304303
pages: PropTypes.array,
305304
activePage: PropTypes.object,
306305
};
@@ -329,7 +328,7 @@ function withRoot(Component) {
329328
};
330329
};
331330

332-
return WithRoot;
331+
return withRouter(WithRoot);
333332
}
334333

335334
export default withRoot;

docs/src/pages/customization/css-in-js/JssRegistry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import CssInJs from './CssInJs';
77
const sheetsRegistry = new SheetsRegistry();
88
const theme = createMuiTheme();
99

10-
class JssRegistry extends React.Component<any, any> {
10+
class JssRegistry extends React.Component {
1111
state = {
1212
length: 0,
1313
};

docs/src/pages/demos/dialogs/ConfirmationDialog.js

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ConfirmationDialog extends React.Component {
3535

3636
state = {};
3737

38+
// TODO
3839
componentWillReceiveProps(nextProps) {
3940
if (nextProps.value !== this.props.value) {
4041
this.setState({ value: nextProps.value });

next.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ module.exports = {
2929

3030
return Object.assign({}, config, {
3131
plugins,
32+
node: {
33+
fs: 'empty',
34+
},
3235
module: Object.assign({}, config.module, {
3336
rules: config.module.rules.concat([
3437
{

packages/material-ui/src/Hidden/HiddenCss.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const styles = theme => {
2828
/**
2929
* @ignore - internal component.
3030
*/
31-
function HiddenCss(props: Props) {
31+
function HiddenCss(props) {
3232
const {
3333
children,
3434
classes,

packages/material-ui/src/Snackbar/Snackbar.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@ class Snackbar extends React.Component {
144144

145145
timerAutoHide = null;
146146

147-
handleMouseEnter = (event: SyntheticUIEvent<>) => {
147+
handleMouseEnter = event => {
148148
if (this.props.onMouseEnter) {
149149
this.props.onMouseEnter(event);
150150
}
151151
this.handlePause();
152152
};
153153

154-
handleMouseLeave = (event: SyntheticUIEvent<>) => {
154+
handleMouseLeave = event => {
155155
if (this.props.onMouseLeave) {
156156
this.props.onMouseLeave(event);
157157
}
158158
this.handleResume();
159159
};
160160

161-
handleClickAway = (event: Event) => {
161+
handleClickAway = event => {
162162
if (this.props.onClose) {
163163
this.props.onClose(event, 'clickaway');
164164
}

packages/material-ui/src/Tabs/Tabs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class Tabs extends React.Component {
152152
};
153153

154154
tabs = undefined;
155-
valueToIndex: { [key: any]: any } = {};
155+
valueToIndex = {};
156156

157157
handleResize = debounce(() => {
158158
this.updateIndicatorState(this.props);
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable import/prefer-default-export */
22

33
import React from 'react';
4-
import type { Node } from 'react';
54
import classNames from 'classnames';
65

76
export function cloneElementWithClassName(child, className) {
@@ -10,16 +9,16 @@ export function cloneElementWithClassName(child, className) {
109
});
1110
}
1211

13-
export function cloneChildrenWithClassName(children: Node, className: string) {
12+
export function cloneChildrenWithClassName(children, className) {
1413
return React.Children.map(children, child => {
1514
return React.isValidElement(child) && cloneElementWithClassName(child, className);
1615
});
1716
}
1817

19-
export function isMuiElement(element: any, muiNames: Array<string>) {
18+
export function isMuiElement(element, muiNames) {
2019
return React.isValidElement(element) && muiNames.indexOf(element.type.muiName) !== -1;
2120
}
2221

23-
export function isMuiComponent(element: any, muiNames: Array<string>) {
22+
export function isMuiComponent(element, muiNames) {
2423
return muiNames.indexOf(element.muiName) !== -1;
2524
}

scripts/get-replacement.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-disable */
2+
// Waiting for https://github.com/kentcdodds/babel-plugin-preval/issues/52
3+
4+
'use strict';
5+
6+
var requireFromString = require('require-from-string');
7+
var objectToAST = require('babel-plugin-preval/dist/object-to-ast');
8+
9+
module.exports = getReplacement;
10+
11+
function getReplacement(_ref) {
12+
var stringToPreval = _ref.string,
13+
filename = _ref.filename,
14+
babel = _ref.babel;
15+
16+
var _babel$transform = babel.transform(stringToPreval, {
17+
filename,
18+
}),
19+
code = _babel$transform.code;
20+
21+
var transpiled = `require('@babel/register');\n${code}`;
22+
var val = requireFromString(transpiled, filename);
23+
return objectToAST(val);
24+
}

0 commit comments

Comments
 (0)