Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2ae9f7d

Browse files
authoredFeb 2, 2021
fix: next 10.0.6 changed prerender-manifest for i18n (#163)
1 parent 6e5c09d commit 2ae9f7d

File tree

5 files changed

+360
-1706
lines changed

5 files changed

+360
-1706
lines changed
 

‎lib/helpers/getPrerenderManifest.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ const transformManifestForI18n = (manifest) => {
1414
if (isDynamicRoute) {
1515
newRoutes[route] = routes[route];
1616
} else {
17-
locales.forEach((locale) => {
18-
const routeWithPrependedLocale =
19-
route === "/" ? `/${locale}` : `/${locale}${route}`;
20-
newRoutes[routeWithPrependedLocale] = {
21-
dataRoute: getDataRouteForRoute(route, locale),
22-
srcRoute: route,
23-
...params,
24-
};
25-
});
17+
const locale = route.split("/")[1];
18+
const routeWithoutLocale = `/${route
19+
.split("/")
20+
.slice(2, route.split("/").length)
21+
.join("/")}`;
22+
newRoutes[route] = {
23+
dataRoute: getDataRouteForRoute(routeWithoutLocale, locale),
24+
srcRoute: routeWithoutLocale,
25+
...params,
26+
};
2627
}
2728
}
2829
);

‎package-lock.json

Lines changed: 243 additions & 1696 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"husky": "^4.3.0",
4545
"jest": "^26.4.2",
4646
"netlify-cli": "^2.61.0",
47-
"next": "^10.0.3",
47+
"next": "^10.0.6",
4848
"prettier": "2.1.1",
4949
"react": "^16.13.1",
5050
"react-dom": "^16.13.1",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Link from "next/link";
2+
3+
const Show = ({ show }) => (
4+
<div>
5+
<p>This page uses getStaticProps() to pre-fetch a TV show.</p>
6+
7+
<hr />
8+
9+
<h1>Show #{show.id}</h1>
10+
<p>{show.name}</p>
11+
12+
<hr />
13+
14+
<Link href="/">
15+
<a>Go back home</a>
16+
</Link>
17+
</div>
18+
);
19+
20+
export async function getStaticProps(context) {
21+
const res = await fetch(`https://api.tvmaze.com/shows/71`);
22+
const data = await res.json();
23+
24+
return {
25+
props: {
26+
show: data,
27+
},
28+
};
29+
}
30+
31+
export default Show;

‎tests/i18n-ssg-root-index.test.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Test next-on-netlify when i18n is set in next.config.js (Next 10+)
2+
3+
const { parse, join, sep } = require("path");
4+
const {
5+
existsSync,
6+
readdirSync,
7+
readFileSync,
8+
readJsonSync,
9+
} = require("fs-extra");
10+
const buildNextApp = require("./helpers/buildNextApp");
11+
12+
// The name of this test file (without extension)
13+
const FILENAME = parse(__filename).name;
14+
15+
// The directory which will be used for testing.
16+
// We simulate a NextJS app within that directory, with pages, and a
17+
// package.json file.
18+
const PROJECT_PATH = join(__dirname, "builds", FILENAME);
19+
20+
const DEFAULT_LOCALE = "en";
21+
22+
// Capture the output to verify successful build
23+
let buildOutput;
24+
25+
beforeAll(
26+
async () => {
27+
buildOutput = await buildNextApp()
28+
.forTest(__filename)
29+
.withPages("pages-i18n-ssg-index")
30+
.withNextConfig("next.config.js-with-i18n.js")
31+
.withPackageJson("package.json")
32+
.build();
33+
},
34+
// time out after 180 seconds
35+
180 * 1000
36+
);
37+
38+
describe("next-on-netlify", () => {
39+
test("builds successfully", () => {
40+
expect(buildOutput).toMatch("Next on Netlify");
41+
expect(buildOutput).toMatch("Success! All done!");
42+
});
43+
});
44+
45+
describe("next-on-netlify", () => {
46+
test("builds successfully", () => {
47+
expect(buildOutput).toMatch("Next on Netlify");
48+
expect(buildOutput).toMatch(
49+
`Copying static NextJS assets to out_publish${sep}`
50+
);
51+
expect(buildOutput).toMatch(
52+
`Setting up API endpoints as Netlify Functions in out_functions${sep}`
53+
);
54+
expect(buildOutput).toMatch(
55+
`Setting up pages with getInitialProps as Netlify Functions in out_functions${sep}`
56+
);
57+
expect(buildOutput).toMatch(
58+
`Setting up pages with getServerSideProps as Netlify Functions in out_functions${sep}`
59+
);
60+
expect(buildOutput).toMatch(
61+
`Copying pre-rendered pages with getStaticProps and JSON data to out_publish${sep}`
62+
);
63+
expect(buildOutput).toMatch(
64+
`Setting up pages with getStaticProps and fallback: true as Netlify Functions in out_functions${sep}`
65+
);
66+
expect(buildOutput).toMatch(
67+
`Setting up pages with getStaticProps and revalidation interval as Netlify Functions in out_functions${sep}`
68+
);
69+
expect(buildOutput).toMatch(
70+
`Copying pre-rendered pages without props to out_publish${sep}`
71+
);
72+
expect(buildOutput).toMatch("Setting up redirects");
73+
expect(buildOutput).toMatch("Success! All done!");
74+
});
75+
});

0 commit comments

Comments
 (0)
This repository has been archived.