From a90530bb2d32a3a67427b20ceda6192499c1577e Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 26 Oct 2018 16:29:30 +0900 Subject: [PATCH] fix makeNextApp.js losing props from withParts.js bug --- .eslintrc | 1 + CHANGELOG.md | 11 +++++++++++ package.json | 2 +- pages/_app.js | 17 +++++++++++++++-- pages/index.js | 15 +++++++++------ pages/page1.js | 14 ++++++++++++++ src/nextjs/makeNextApp.js | 16 +++++++++++++++- 7 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 pages/page1.js diff --git a/.eslintrc b/.eslintrc index 60c5ffe..18c8424 100644 --- a/.eslintrc +++ b/.eslintrc @@ -27,6 +27,7 @@ "react/jsx-no-bind": 2, "react/no-multi-comp": 0, "react/jsx-closing-tag-location": 0, + "react/jsx-one-expression-per-line": 0, "arrow-body-style": 0, "prefer-arrow-callback": 0, "semi": 1, diff --git a/CHANGELOG.md b/CHANGELOG.md index 38a9da4..9aa3c56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ ### [Versions](https://github.com/thundermiracle/next-mui-helper/releases/) +## 1.1.1 +###### *Oct 26, 2018* + +#### Breaking Changes + +N/A + +#### Changes + +- Fix the bug of makeNextApp.js losing props in hoc + ## 1.1.0 ###### *Oct 24, 2018* diff --git a/package.json b/package.json index b73fbc0..5b04f58 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-mui-helper", - "version": "1.1.0", + "version": "1.1.1", "description": "hocs for making material-ui project with next.js(SSR)", "main": "./src/mui/withParts.js", "scripts": { diff --git a/pages/_app.js b/pages/_app.js index d7e503a..256f24c 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -1,3 +1,16 @@ -import { DefaultNextApp } from '../src/nextjs/makeNextApp'; +import React from 'react'; -export default DefaultNextApp; +import makeNextApp from '../src/nextjs/makeNextApp'; + +const Layout = (props) => { + return ( +
+ [Layout] +
+ {props.children} +
+
+ ); +}; + +export default makeNextApp(null, Layout); diff --git a/pages/index.js b/pages/index.js index 2eb998a..68b7327 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,11 +1,14 @@ import React from 'react'; import Button from '@material-ui/core/Button'; -import { defaultParts } from '../src/mui/withParts'; +import Link from 'next/link'; -const Page1 = () => ( - +const Index = () => ( +
+ + + + +
); -export default defaultParts(Page1); +export default Index; diff --git a/pages/page1.js b/pages/page1.js new file mode 100644 index 0000000..9849697 --- /dev/null +++ b/pages/page1.js @@ -0,0 +1,14 @@ +import React from 'react'; +import Button from '@material-ui/core/Button'; +import Link from 'next/link'; + +const Index = () => ( +
+ Page1 contentsssssssssssssss... + + + +
+); + +export default Index; diff --git a/src/nextjs/makeNextApp.js b/src/nextjs/makeNextApp.js index 1e600eb..cad710e 100644 --- a/src/nextjs/makeNextApp.js +++ b/src/nextjs/makeNextApp.js @@ -3,10 +3,24 @@ import App, { Container } from 'next/app'; import withParts from '../mui/withParts'; const makeNextApp = (muiTheme, Layout, enableNProgress, enableDefaultCssBaseline) => { + const hocs = withParts(muiTheme, Layout, enableNProgress, enableDefaultCssBaseline); class NextApp extends App { + // inject props made by hoc + static async getInitialProps({ Component, ctx }) { + let pageProps = {}; + + const ComponentWithInitialProps = hocs(Component); + + if (ComponentWithInitialProps.getInitialProps) { + pageProps = await ComponentWithInitialProps.getInitialProps(ctx); + } + + return { pageProps }; + } + render() { const { Component, pageProps } = this.props; - const NewComponent = withParts(muiTheme, Layout, enableNProgress, enableDefaultCssBaseline)(Component); + const NewComponent = hocs(Component); return (