Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/runtime/src/helpers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { RouteHas } from 'next/dist/lib/load-custom-routes'
import { outdent } from 'outdent'

import { getRequiredServerFiles, NextConfig } from './config'
import { makeLocaleOptional, stripLookahead } from './matchers'
import { makeLocaleOptional, stripLookahead, transformCaptureGroups } from './matchers'

// This is the format as of [email protected]
interface EdgeFunctionDefinitionV1 {
Expand Down Expand Up @@ -237,7 +237,7 @@ const writeEdgeFunction = async ({

// We add a defintion for each matching path
return matchers.map((matcher) => {
const pattern = stripLookahead(matcher.regexp)
const pattern = transformCaptureGroups(stripLookahead(matcher.regexp))
return { function: name, pattern, name: edgeFunctionDefinition.name }
})
}
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime/src/helpers/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const stripLookahead = (regex: string) => {
}
}

// The Go regexp lib has alternative syntax for named capture groups
export const transformCaptureGroups = (regex: string) => regex.replace(/\(\?\<\w+\>/, '(')

const LOCALIZED_REGEX_PREFIX = '(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/([^/.]{1,}))'
const OPTIONAL_REGEX_PREFIX = '(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/([^/.]{1,}))?'

Expand Down