@@ -21,7 +21,19 @@ function generateRegexFromPattern(pattern: string): string {
2121}
2222
2323export function onBuildComplete ( ctx : OnBuildCompleteContext , frameworksAPIConfigArg : any ) {
24- let frameworksAPIConfig : any = frameworksAPIConfigArg
24+ const frameworksAPIConfig : any = frameworksAPIConfigArg ?? { }
25+
26+ // when migrating from @netlify /plugin-nextjs@4 image redirect to ipx might be cached in the browser
27+ frameworksAPIConfig . redirects ??= [ ]
28+ frameworksAPIConfig . redirects . push ( {
29+ from : '/_ipx/*' ,
30+ // w and q are too short to be used as params with id-length rule
31+ // but we are forced to do so because of the next/image loader decides on their names
32+ // eslint-disable-next-line id-length
33+ query : { url : ':url' , w : ':width' , q : ':quality' } ,
34+ to : '/.netlify/images?url=:url&w=:width&q=:quality' ,
35+ status : 200 ,
36+ } )
2537
2638 const { images } = ctx . config
2739 if ( images . loader === 'custom' && images . loaderFile === NETLIFY_IMAGE_LOADER_FILE ) {
@@ -83,7 +95,6 @@ export function onBuildComplete(ctx: OnBuildCompleteContext, frameworksAPIConfig
8395
8496 if ( remoteImageSources . length !== 0 ) {
8597 // https://docs.netlify.com/build/frameworks/frameworks-api/#images
86- frameworksAPIConfig ??= { }
8798 frameworksAPIConfig . images ??= { }
8899 frameworksAPIConfig . images . remote_images = remoteImageSources
89100 }
0 commit comments