-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle ipx redirect that visitors might have browser cached from…
… v4 (#390) * test: add setup replicating runtime v4 next/image handling to test handling of potentially browser-cached v4 image handling redirects * fix: handle ipx redirect that visitors might have browser cached from v4
- Loading branch information
Showing
6 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/fixtures/simple-next-app/app/image/migration-from-v4-runtime/next-image-runtime-v4.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Moved to separate component marked with "use client" to avoid the following error when attempting to do similar on page itself | ||
// Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". | ||
// {0: ..., loader: function} | ||
|
||
'use client' | ||
|
||
import Image from 'next/image' | ||
|
||
function RuntimeV4SimulatorImageLoader({ src, width, quality }) { | ||
// replicate default Next.js image loader, just using custom endpoint that will simulate the runtime V4 behavior | ||
// https://github.com/vercel/next.js/blob/c9439b5654432df6488e178e5ade6f4ad2d1cf6a/packages/next/src/shared/lib/image-loader.ts#L60 | ||
return `/_nextRuntimeV4ImageHandler?url=${encodeURIComponent(src)}&w=${width}&q=${quality || 75}` | ||
} | ||
|
||
export function NextImageWithLoaderSimulatingRuntimeV4(props) { | ||
return <Image {...props} loader={RuntimeV4SimulatorImageLoader} /> | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/fixtures/simple-next-app/app/image/migration-from-v4-runtime/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NextImageWithLoaderSimulatingRuntimeV4 } from './next-image-runtime-v4' | ||
|
||
export default function NextImageUsingNetlifyImageCDN() { | ||
return ( | ||
<main> | ||
<h1>Next/Image + Netlify Image CDN</h1> | ||
<NextImageWithLoaderSimulatingRuntimeV4 | ||
src="/squirrel.jpg" | ||
alt="a cute squirrel (next/image)" | ||
width={300} | ||
height={278} | ||
/> | ||
</main> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters