This repository was archived by the owner on Jan 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +64
-2
lines changed
pages/revalidated-ssg-pages-2 Expand file tree Collapse file tree 5 files changed +64
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ describe("ISR Tests", () => {
6
6
describe ( "SSG page" , ( ) => {
7
7
[
8
8
{ path : "/revalidated-ssg-page" , initialWaitSeconds : 0 } ,
9
+ // Page with spaces in it (generally not recommended since this is not URL-safe character, but Next.js handles this)
10
+ { path : "/revalidated-ssg-pages-2/with%20space" , initialWaitSeconds : 0 } ,
9
11
// Pre-rendered ISR page
10
12
{ path : "/revalidated-ssg-pages/101" , initialWaitSeconds : 0 } ,
11
13
// Blocking dynamic generated page. As the page will be created and cached
Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+ import { GetStaticPaths , GetStaticPropsResult } from "next" ;
3
+
4
+ type SSGPageProps = {
5
+ date : string ;
6
+ } ;
7
+
8
+ export default function RevalidatedSSGPage ( props : SSGPageProps ) : JSX . Element {
9
+ return (
10
+ < React . Fragment >
11
+ < div >
12
+ < p data-cy = "date-text" > { props . date } </ p >
13
+ </ div >
14
+ </ React . Fragment >
15
+ ) ;
16
+ }
17
+
18
+ export function getStaticPaths ( ) {
19
+ const paths = [ { params : { title : "with space" } } ] ;
20
+ return { paths, fallback : true } ;
21
+ }
22
+
23
+ export function getStaticProps ( ) : GetStaticPropsResult < SSGPageProps > {
24
+ return {
25
+ revalidate : 10 ,
26
+ props : {
27
+ date : new Date ( ) . toJSON ( )
28
+ }
29
+ } ;
30
+ }
Original file line number Diff line number Diff line change @@ -119,7 +119,9 @@ const staticRequest = async (
119
119
platformClient : PlatformClient
120
120
) => {
121
121
const basePath = routesManifest . basePath ;
122
- const fileKey = ( path + file ) . slice ( 1 ) ; // need to remove leading slash from path for page/file key
122
+ const fileKey = ( path + decodeURI ( file ) ) . slice ( 1 ) ; // need to remove leading slash from path for page/file key
123
+ // also decode file parameter as it's encoded
124
+ // (legacy reasons since previously Cloudfront request is used to request S3, and CF requires an encoded request.uri)
123
125
124
126
const staticRoute = route . isStatic ? ( route as StaticRoute ) : undefined ;
125
127
const statusCode = route ?. statusCode ?? 200 ;
Original file line number Diff line number Diff line change @@ -78,6 +78,34 @@ export const handlePageReq = (
78
78
statusCode
79
79
} ;
80
80
}
81
+ // Handle ISR pages with encoded URL
82
+ // This only applies to ISR, other pages should not be resolved if sent with encoded characters (same as local Next.js server behavior)
83
+ const decodedLocaleUri = decodeURI ( localeUri ) ;
84
+ if ( pages . ssg . nonDynamic [ decodedLocaleUri ] && ! isPreview ) {
85
+ const ssg = pages . ssg . nonDynamic [ decodedLocaleUri ] ;
86
+ if ( ssg . initialRevalidateSeconds ) {
87
+ const route = ssg . srcRoute ?? decodedLocaleUri ;
88
+ const nonLocaleUri = dropLocaleFromPath (
89
+ decodedLocaleUri ,
90
+ routesManifest
91
+ ) ;
92
+ const statusCode =
93
+ nonLocaleUri === "/404"
94
+ ? 404
95
+ : nonLocaleUri === "/500"
96
+ ? 500
97
+ : undefined ;
98
+ return {
99
+ isData : false ,
100
+ isStatic : true ,
101
+ file : pageHtml ( localeUri ) , // Use encoded localeUri instead of decodedLocaleUri as this is used by CloudFront request that needs an encoded URL
102
+ // page JS path is from SSR entries in manifest
103
+ page : pages . ssr . nonDynamic [ route ] || pages . ssr . dynamic [ route ] ,
104
+ revalidate : ssg . initialRevalidateSeconds ,
105
+ statusCode
106
+ } ;
107
+ }
108
+ }
81
109
if ( ( pages . ssg . notFound ?? { } ) [ localeUri ] && ! isPreview ) {
82
110
return notFoundPage ( uri , manifest , routesManifest ) ;
83
111
}
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export const handler = async (event: AWSLambda.SQSEvent): Promise<void> => {
29
29
"passthrough"
30
30
) ;
31
31
32
- const normalizedUri = regenerationEvent . pageS3Path
32
+ const normalizedUri = decodeURI ( regenerationEvent . pageS3Path )
33
33
. replace ( `static-pages/${ manifest . buildId } ` , "" )
34
34
. replace ( ".js" , "" ) ;
35
35
You can’t perform that action at this time.
0 commit comments