Skip to content

Commit

Permalink
Make sure the Next.js Image Context is reused instead of recreated
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnabhan committed Aug 18, 2023
1 parent 3dfc417 commit 52961b7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion code/frameworks/nextjs/src/images/decorator.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import type { Addon_StoryContext } from '@storybook/types';
import { ImageContext } from './context';

const { ImageContext } = __non_webpack_require__('./images/context');

export const ImageDecorator = (
Story: React.FC,
Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/nextjs/src/images/next-future-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type * as _NextImage from 'next/image';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore import is aliased in webpack config
import OriginalNextFutureImage from 'sb-original/next/future/image';
import { ImageContext } from './context';
import { defaultLoader } from './next-image-default-loader';

const { ImageContext } = __non_webpack_require__('./context');

function NextFutureImage(props: _NextImage.ImageProps) {
const imageParameters = React.useContext(ImageContext);

Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/nextjs/src/images/next-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import OriginalNextImage from 'sb-original/next/image';
import type * as _NextImage from 'next/image';
import React from 'react';
import { ImageContext } from './context';
import { defaultLoader } from './next-image-default-loader';

const { ImageContext } = __non_webpack_require__('./context');

const MockedNextImage = (props: _NextImage.ImageProps) => {
const imageParameters = React.useContext(ImageContext);

Expand Down
3 changes: 2 additions & 1 deletion code/frameworks/nextjs/src/images/next-legacy-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import OriginalNextLegacyImage from 'sb-original/next/legacy/image';
import type * as _NextLegacyImage from 'next/legacy/image';
import React from 'react';
import { ImageContext } from './context';
import { defaultLoader } from './next-image-default-loader';

const { ImageContext } = __non_webpack_require__('./context');

function NextLegacyImage(props: _NextLegacyImage.ImageProps) {
const imageParameters = React.useContext(ImageContext);

Expand Down

0 comments on commit 52961b7

Please sign in to comment.