Skip to content

fix: strip domain from ipx edge functions path (#2098) #2099

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 5 commits into from
Jun 12, 2023

Conversation

zachleat
Copy link

@zachleat zachleat commented May 10, 2023

Summary

When folks put in a full URL into the images.path configuration while using Edge functions for image format content negotiation, the Edge function never runs, as full URLs are not supported for Edge function paths (in Netlify).

Strictly speaking in your next.config.js:

module.exports = {
  images: {
    path: `https://example.com/_next/image`,
  },
}

The PR changes the Edge function to capture /_next/image instead of (previously erroring) https://example.com/_next/image. It does not affect the generated markup.

See #2098 for more info.

Potential issues:

  • if a project is using a loader other than default (the code assumes that opting into edge function images means they’re using the default loader)
  • when the Edge functions team circles back and adds support for domain-level Edge declarations, we’ll need to also circle back and remove this change.

Test plan

Would appreciate some additional guidance here! I did attempt to put together a sample repo but encountered some errors when attempting to npm install github:netlify/next-runtime#zl/next-images-path-edge.

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

Fixes #2098

image

Standard checks:

  • Check the Deploy Preview's Demo site for your PR's functionality
  • Add docs when necessary

🧪 Once merged, make sure to update the version if needed and that it was published correctly.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/6487269eefb7980008186a7b
😎 Deploy Preview https://deploy-preview-2099--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/6487269e9fa38b00083d865c
😎 Deploy Preview https://deploy-preview-2099--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/6487269e0c777d0007fa0791
😎 Deploy Preview https://deploy-preview-2099--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label May 10, 2023
@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/6487269e9fa38b00083d8661
😎 Deploy Preview https://deploy-preview-2099--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/6487269e91208600082df9d9
😎 Deploy Preview https://deploy-preview-2099--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/6487269e815cf80008e5ddd4
😎 Deploy Preview https://deploy-preview-2099--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/6487269e0b901c000889cbd3
😎 Deploy Preview https://deploy-preview-2099--next-plugin-canary.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/6487269e3fe24100084300a3
😎 Deploy Preview https://deploy-preview-2099--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented May 10, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 35c1234
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/6487269e0b901c000889cbd1
😎 Deploy Preview https://deploy-preview-2099--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

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

This looks great @zachleat!

/**
* Convert the images path to strip the origin (until domain-level Edge functions are supported)
*/
const sanitizeEdgePath = (imagesPath: string) => new URL(imagesPath, process.env.URL || 'http://n').pathname

Choose a reason for hiding this comment

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

Nice using new URL. This fix looks good.

manifest.functions.push({
function: 'ipx',
name: 'next/image handler',
path: nextConfig.images.path || '/_next/image',
path: nextConfig.images.path ? sanitizeEdgePath(nextConfig.images.path) : '/_next/image',

Choose a reason for hiding this comment

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

It'd be good to either have a unit test checking that it gets sanitized when needed or we could update a demo site with a full images path in a Next config to validate the fix.

@nolessafool
Copy link

it's been awhile since @nickytonline 's review 2 weeks ago - but we have enterprise customers actively awaiting this to be shipped:

Can we wrap this up soon?

@zachleat zachleat requested a review from a team as a code owner June 7, 2023 21:45
@zachleat
Copy link
Author

zachleat commented Jun 7, 2023

@nickytonline I added a few unit tests here, can you have a look? thanks!

@kodiakhq kodiakhq bot merged commit c9ab983 into main Jun 12, 2023
@kodiakhq kodiakhq bot deleted the zl/next-images-path-edge branch June 12, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Full domain URLs in images.path config bypass Edge functions
5 participants