-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21909 from martinnabhan/next-image-disable-lazy-l…
…oading Allow disabling next/image lazy loading
- Loading branch information
1 parent
40f4981
commit 533bc69
Showing
7 changed files
with
119 additions
and
7 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
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,16 @@ | ||
import { createContext } from 'react'; | ||
import type { ImageProps, StaticImageData } from 'next/image'; | ||
import type { ImageProps as LegacyImageProps } from 'next/legacy/image'; | ||
|
||
// StaticRequire needs to be in scope for the TypeScript compiler to work. | ||
// See: https://github.com/microsoft/TypeScript/issues/5711 | ||
// Since next/image doesn't export StaticRequire we need to re-define it here and set src's type to it. | ||
interface StaticRequire { | ||
default: StaticImageData; | ||
} | ||
|
||
declare type StaticImport = StaticRequire | StaticImageData; | ||
|
||
export const ImageContext = createContext< | ||
Partial<Omit<ImageProps, 'src'> & { src: string | StaticImport }> & Omit<LegacyImageProps, 'src'> | ||
>({}); |
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,18 @@ | ||
import * as React from 'react'; | ||
import type { Addon_StoryContext } from '@storybook/types'; | ||
import { ImageContext } from './context'; | ||
|
||
export const ImageDecorator = ( | ||
Story: React.FC, | ||
{ parameters }: Addon_StoryContext | ||
): React.ReactNode => { | ||
if (!parameters.nextjs?.image) { | ||
return <Story />; | ||
} | ||
|
||
return ( | ||
<ImageContext.Provider value={parameters.nextjs.image}> | ||
<Story /> | ||
</ImageContext.Provider> | ||
); | ||
}; |
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
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