Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: handle case of env not being defined for edge functions #2936

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

Merged
merged 2 commits into from
May 19, 2025
Merged
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
8 changes: 5 additions & 3 deletions src/build/functions/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ const copyHandlerDependencies = async (

const outputFile = join(destDir, `server/${name}.js`)

// Prepare environment variables for draft-mode (i.e. __NEXT_PREVIEW_MODE_ID, __NEXT_PREVIEW_MODE_SIGNING_KEY, __NEXT_PREVIEW_MODE_ENCRYPTION_KEY)
for (const [key, value] of Object.entries(env)) {
parts.push(`process.env.${key} = '${value}';`)
if (env) {
// Prepare environment variables for draft-mode (i.e. __NEXT_PREVIEW_MODE_ID, __NEXT_PREVIEW_MODE_SIGNING_KEY, __NEXT_PREVIEW_MODE_ENCRYPTION_KEY)
for (const [key, value] of Object.entries(env)) {
parts.push(`process.env.${key} = '${value}';`)
}
Comment on lines +135 to +139
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/opennextjs/opennextjs-netlify/actions/runs/15105688788/job/42453967192#step:14:1785

next@^13 did not have env defined (it was added in vercel/next.js@dcff078 ), so we need to check if it's defined first

}

if (wasm?.length) {
Expand Down
2 changes: 1 addition & 1 deletion tests/netlify-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class NextDeployInstance extends NextInstance {

try {
const deployUrlRegex = new RegExp(
/https:\/\/app\.netlify\.com\/sites\/(?<siteName>[^\/]+)\/deploys\/(?<deployID>[0-9a-f]+)/gm,
/https:\/\/app\.netlify\.com\/(sites|projects)\/(?<siteName>[^\/]+)\/deploys\/(?<deployID>[0-9a-f]+)/gm,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's projects now, but kept old one in there in case there would be any kind of revert on that

).exec(deployRes.stdout)
const [buildLogsUrl] = deployUrlRegex || []
const { deployID, siteName } = deployUrlRegex?.groups || {}
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/create-e2e-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async function deploySite(

const { siteName, deployID } =
new RegExp(
/app\.netlify\.com\/sites\/(?<siteName>[^\/]+)\/deploys\/(?<deployID>[0-9a-f]+)/gm,
/app\.netlify\.com\/(sites|projects)\/(?<siteName>[^\/]+)\/deploys\/(?<deployID>[0-9a-f]+)/gm,
).exec(output)?.groups || {}

if (!deployID) {
Expand Down
Loading