Skip to content

fix: enforce a single edge entrypoint for next edge handler #2866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
17 changes: 9 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@netlify/blobs": "^8.2.0",
"@netlify/build": "^32.1.0",
"@netlify/edge-bundler": "^13.0.2",
"@netlify/edge-functions": "^2.11.1",
"@netlify/edge-functions": "^2.12.0",
"@netlify/eslint-config-node": "^7.0.1",
"@netlify/functions": "^3.0.4",
"@netlify/serverless-functions-api": "^1.38.0",
Expand Down
1 change: 0 additions & 1 deletion run-local-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ cd ../next.js/
git apply $RUNTIME_DIR/tests/e2e-utils.patch || git apply $RUNTIME_DIR/tests/e2e-utils-v2.patch
node run-tests.js --type e2e --debug --test-pattern $1
git checkout -- test/lib/e2e-utils.ts

27 changes: 14 additions & 13 deletions src/build/functions/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,25 @@ const getHandlerName = ({ name }: Pick<NextDefinition, 'name'>): string =>
const buildHandlerDefinition = (
ctx: PluginContext,
{ name, matchers, page }: NextDefinition,
): Array<ManifestFunction> => {
const fun = getHandlerName({ name })
const funName = name.endsWith('middleware')
): ManifestFunction => {
const functionHandlerName = getHandlerName({ name })
const functionName = name.endsWith('middleware')
? 'Next.js Middleware Handler'
: `Next.js Edge Handler: ${page}`
const cache = name.endsWith('middleware') ? undefined : ('manual' as const)
const generator = `${ctx.pluginName}@${ctx.pluginVersion}`

return augmentMatchers(matchers, ctx).map((matcher) => ({
function: fun,
name: funName,
pattern: matcher.regexp,
const i18nAugmentedMatchers = augmentMatchers(matchers, ctx)
const combinedEdgeHandlerRegex = i18nAugmentedMatchers
.map((matcher) => `(${matcher.regexp})`)
.join('|')

return {
function: functionHandlerName,
name: functionName,
pattern: combinedEdgeHandlerRegex,
cache,
generator,
}))
}
}

export const clearStaleEdgeHandlers = async (ctx: PluginContext) => {
Expand All @@ -183,10 +187,7 @@ export const clearStaleEdgeHandlers = async (ctx: PluginContext) => {

export const createEdgeHandlers = async (ctx: PluginContext) => {
const nextManifest = await ctx.getMiddlewareManifest()
const nextDefinitions = [
...Object.values(nextManifest.middleware),
// ...Object.values(nextManifest.functions)
]
const nextDefinitions = [...Object.values(nextManifest.middleware)]
await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def)))

const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def))
Expand Down
2 changes: 1 addition & 1 deletion tests/prepare.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
// this installs and builds all the fixtures
// Needed to run before executing the integration tests
import { existsSync, readdirSync } from 'node:fs'
import { readdirSync } from 'node:fs'
import { rm, readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { argv } from 'node:process'
Expand Down
Loading