Skip to content

Commit 98940da

Browse files
authored
fix(nextjs-ssr): fix hydrate issue on shop page (#2729)
1 parent 9abf098 commit 98940da

File tree

6 files changed

+1368
-14
lines changed

6 files changed

+1368
-14
lines changed

nextjs-ssr/checkout/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"start": "NODE_ENV=production next start"
99
},
1010
"dependencies": {
11-
"@module-federation/nextjs-mf": "5.11.5",
11+
"@module-federation/nextjs-mf": "6.0.7",
1212
"lodash": "4.17.21",
1313
"next": "12.2.2",
14-
"next-compose-plugins": "^2.2.1",
14+
"next-compose-plugins": "2.2.1",
1515
"nextjs-shared": "file:../shared",
16-
"react": "^18.2.0",
17-
"react-dom": "^18.2.0",
16+
"react": "18.2.0",
17+
"react-dom": "18.2.0",
1818
"webpack": "5.72.1",
1919
"webpack-merge": "^5.8.0"
2020
}

nextjs-ssr/home/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"start": "NODE_ENV=production next start -p 3001"
99
},
1010
"dependencies": {
11-
"@module-federation/nextjs-mf": "5.11.5",
11+
"@module-federation/nextjs-mf": "6.0.7",
1212
"lodash": "4.17.21",
1313
"next": "12.2.2",
14-
"next-compose-plugins": "^2.2.1",
14+
"next-compose-plugins": "2.2.1",
1515
"nextjs-shared": "file:../shared",
16-
"react": "^18.2.0",
17-
"react-dom": "^18.2.0",
16+
"react": "18.2.0",
17+
"react-dom": "18.2.0",
1818
"webpack": "5.72.1",
1919
"webpack-merge": "^5.8.0"
2020
}

nextjs-ssr/shop/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
"start": "NODE_ENV=production next start -p 3002"
99
},
1010
"dependencies": {
11-
"@module-federation/nextjs-mf": "5.11.5",
11+
"@module-federation/nextjs-mf": "6.0.7",
1212
"lodash": "4.17.21",
1313
"next": "12.2.2",
14-
"next-compose-plugins": "^2.2.1",
14+
"next-compose-plugins": "2.2.1",
1515
"nextjs-shared": "file:../shared",
16-
"react": "^18.2.0",
17-
"react-dom": "^18.2.0",
16+
"react": "18.2.0",
17+
"react-dom": "18.2.0",
1818
"webpack": "5.72.1",
1919
"webpack-merge": "^5.8.0"
2020
}

nextjs-ssr/shop/pages/_app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1+
import { Suspense } from "react";
12
import App from 'next/app';
23
import dynamic from 'next/dynamic';
3-
const Nav = dynamic(() => import('home/nav'));
4+
const Nav = dynamic(() => import('home/nav') ,{suspense:true});
45

56
function MyApp({ Component, pageProps }) {
67
return (
78
<>
9+
<Suspense fallback={'loading'}>
810
<Nav />
11+
</Suspense>
912
<Component {...pageProps} />
1013
</>
1114
);
1215
}
16+
1317
MyApp.getInitialProps = async ctx => {
1418
const appProps = await App.getInitialProps(ctx);
1519
return appProps;

nextjs-ssr/shop/pages/shop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Shop = props => (
3232
</div>
3333
);
3434
Shop.getInitialProps = async () => {
35-
const swapi = await fetch('https://swapi.dev/api/people/1').then(res => res.json());
35+
const swapi = await fetch('https://jsonplaceholder.typicode.com/todos/2').then(res => res.json());
3636
return swapi;
3737
};
3838
export default Shop;

0 commit comments

Comments
 (0)