-
Notifications
You must be signed in to change notification settings - Fork 89
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
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
There was a problem hiding this 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!
packages/runtime/src/helpers/edge.ts
Outdated
/** | ||
* 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 |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
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? |
@nickytonline I added a few unit tests here, can you have a look? thanks! |
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
: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:
loader
other thandefault
(the code assumes that opting into edge function images means they’re using thedefault
loader)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
Standard checks:
🧪 Once merged, make sure to update the version if needed and that it was published correctly.