Skip to content

Commit 5b931af

Browse files
authored
[next] Ensure $$ in ISR page is handled correctly (vercel#8359)
* Ensure $$ in ISR page is handled correctly * update test * Remove duplicate tests * add comment * tweak
1 parent 1508036 commit 5b931af

File tree

9 files changed

+183
-1
lines changed

9 files changed

+183
-1
lines changed

packages/next/src/utils.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,10 @@ export const onPrerenderRoute =
18321832
if (nonDynamicSsg || isFallback || isOmitted) {
18331833
outputPathData = outputPathData.replace(
18341834
new RegExp(`${escapeStringRegexp(origRouteFileNoExt)}.json$`),
1835-
`${routeFileNoExt}.json`
1835+
// ensure we escape "$" correctly while replacing as "$" is a special
1836+
// character, we need to do double escaping as first is for the initial
1837+
// replace on the routeFile and then the second on the outputPath
1838+
`${routeFileNoExt.replace(/\$/g, '$$$$')}.json`
18361839
);
18371840
}
18381841

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function Page({ date }) {
2+
return (
3+
<>
4+
<h1>$$</h1>
5+
<p>Date: {date}</p>
6+
</>
7+
);
8+
}
9+
10+
export async function getStaticProps() {
11+
return {
12+
props: {
13+
date: new Date().toISOString(),
14+
page: '$$',
15+
},
16+
};
17+
}
18+
19+
export default Page;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Page({ date }) {
2+
return (
3+
<>
4+
<h1>$$b</h1>
5+
<p>Date: {date}</p>
6+
</>
7+
);
8+
}
9+
10+
export async function getStaticProps() {
11+
return {
12+
props: {
13+
date: new Date().toISOString(),
14+
page: '$$b',
15+
},
16+
revalidate: 5,
17+
};
18+
}
19+
20+
export default Page;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Page({ date }) {
2+
return (
3+
<>
4+
<h1>b$$</h1>
5+
<p>Date: {date}</p>
6+
</>
7+
);
8+
}
9+
10+
export async function getStaticProps() {
11+
return {
12+
props: {
13+
date: new Date().toISOString(),
14+
page: 'b$$',
15+
},
16+
revalidate: 5,
17+
};
18+
}
19+
20+
export default Page;

packages/next/test/fixtures/00-i18n-support/vercel.json

+30
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@
77
}
88
],
99
"probes": [
10+
{
11+
"path": "/$$",
12+
"status": 200,
13+
"mustContain": ">$$<"
14+
},
15+
{
16+
"path": "/_next/data/testing-build-id/en/$$.json",
17+
"status": 200,
18+
"mustContain": "\"$$\""
19+
},
20+
{
21+
"path": "/$$b",
22+
"status": 200,
23+
"mustContain": ">$$b<"
24+
},
25+
{
26+
"path": "/_next/data/testing-build-id/en/$$b.json",
27+
"status": 200,
28+
"mustContain": "\"$$b\""
29+
},
30+
{
31+
"path": "/b$$",
32+
"status": 200,
33+
"mustContain": ">b$$<"
34+
},
35+
{
36+
"path": "/_next/data/testing-build-id/en/b$$.json",
37+
"status": 200,
38+
"mustContain": "\"b$$\""
39+
},
1040
{
1141
"path": "/",
1242
"headers": {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Page({ date }) {
2+
return (
3+
<>
4+
<h1>$$</h1>
5+
<p>Date: {date}</p>
6+
</>
7+
);
8+
}
9+
10+
export async function getStaticProps() {
11+
return {
12+
props: {
13+
date: new Date().toISOString(),
14+
page: '$$',
15+
},
16+
revalidate: 5,
17+
};
18+
}
19+
20+
export default Page;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Page({ date }) {
2+
return (
3+
<>
4+
<h1>$$b</h1>
5+
<p>Date: {date}</p>
6+
</>
7+
);
8+
}
9+
10+
export async function getStaticProps() {
11+
return {
12+
props: {
13+
date: new Date().toISOString(),
14+
page: '$$b',
15+
},
16+
revalidate: 5,
17+
};
18+
}
19+
20+
export default Page;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function Page({ date }) {
2+
return (
3+
<>
4+
<h1>b$$</h1>
5+
<p>Date: {date}</p>
6+
</>
7+
);
8+
}
9+
10+
export async function getStaticProps() {
11+
return {
12+
props: {
13+
date: new Date().toISOString(),
14+
page: 'b$$',
15+
},
16+
revalidate: 5,
17+
};
18+
}
19+
20+
export default Page;

packages/next/test/fixtures/00-server-build/vercel.json

+30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,36 @@
2626
}
2727
],
2828
"probes": [
29+
{
30+
"path": "/$$",
31+
"status": 200,
32+
"mustContain": ">$$<"
33+
},
34+
{
35+
"path": "/_next/data/testing-build-id/$$.json",
36+
"status": 200,
37+
"mustContain": "\"$$\""
38+
},
39+
{
40+
"path": "/$$b",
41+
"status": 200,
42+
"mustContain": ">$$b<"
43+
},
44+
{
45+
"path": "/_next/data/testing-build-id/$$b.json",
46+
"status": 200,
47+
"mustContain": "\"$$b\""
48+
},
49+
{
50+
"path": "/b$$",
51+
"status": 200,
52+
"mustContain": ">b$$<"
53+
},
54+
{
55+
"path": "/_next/data/testing-build-id/b$$.json",
56+
"status": 200,
57+
"mustContain": "\"b$$\""
58+
},
2959
{
3060
"path": "/",
3161
"status": 200,

0 commit comments

Comments
 (0)