Skip to content

Commit 4e8daa5

Browse files
committed
fix: consolidated static route matching for revalidate with i18n
1 parent d53a11d commit 4e8daa5

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

packages/runtime/src/templates/server.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,35 +72,28 @@ class NetlifyNextServer extends NextServer {
7272
const { i18n } = this.nextConfig
7373
const { routes, dynamicRoutes } = this.netlifyPrerenderManifest
7474

75-
// matches static non-i18n routes
76-
const normalizedRoute = normalizeRoute(route)
75+
// matches static routes
76+
const normalizedRoute = normalizeRoute(i18n ? localizeRoute(route, i18n) : route)
7777
if (normalizedRoute in routes) {
7878
const { dataRoute } = routes[normalizedRoute]
79-
return [route, dataRoute]
80-
}
81-
82-
// matches static i18n routes
83-
if (i18n) {
84-
const localizedRoute = localizeRoute(normalizedRoute, i18n)
85-
if (localizedRoute in routes) {
86-
const dataRoute = localizeDataRoute(routes[localizedRoute].dataRoute, localizedRoute)
87-
return [route, dataRoute]
88-
}
79+
const normalizedDataRoute = i18n ? localizeDataRoute(dataRoute, normalizedRoute) : dataRoute
80+
return [route, normalizedDataRoute]
8981
}
9082

9183
// matches dynamic routes
84+
const unlocalizedRoute = i18n ? unlocalizeRoute(normalizedRoute, i18n) : normalizedRoute
9285
for (const dynamicRoute in dynamicRoutes) {
93-
const unlocalizedRoute = i18n ? unlocalizeRoute(normalizedRoute, i18n) : normalizedRoute
94-
const matches = unlocalizedRoute.match(dynamicRoutes[dynamicRoute].routeRegex)
86+
const { dataRoute, routeRegex } = dynamicRoutes[dynamicRoute]
87+
const matches = unlocalizedRoute.match(routeRegex)
9588
if (matches && matches.length !== 0) {
9689
// remove the first match, which is the full route
9790
matches.shift()
9891
// replace the dynamic segments with the actual values
99-
const interpolatedDataRoute = dynamicRoutes[dynamicRoute].dataRoute.replace(/\[(.*?)]/g, () => matches.shift())
100-
const dataRoute = i18n
101-
? localizeDataRoute(interpolatedDataRoute, localizeRoute(normalizedRoute, i18n))
92+
const interpolatedDataRoute = dataRoute.replace(/\[(.*?)]/g, () => matches.shift())
93+
const normalizedDataRoute = i18n
94+
? localizeDataRoute(interpolatedDataRoute, normalizedRoute)
10295
: interpolatedDataRoute
103-
return [route, dataRoute]
96+
return [route, normalizedDataRoute]
10497
}
10598
}
10699

0 commit comments

Comments
 (0)