Skip to content

Commit

Permalink
fix: wrap Image component to prevent SSR issues
Browse files Browse the repository at this point in the history
This is related to hashicorp/next-mdx-remote#405
When Image is used directly it produces error when server rendered.
Wrapping it allows server to render the component without issues.
  • Loading branch information
ethernal committed Oct 19, 2023
1 parent 34483a1 commit 72de330
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/components/ImageSSR/ImageSSR.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Image, { ImageProps } from 'next/image';
import * as React from 'react';

function ImageSSR(props: ImageProps) {
return <Image {...props} />;
}

export default ImageSSR;
2 changes: 2 additions & 0 deletions src/components/ImageSSR/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ImageSSR';
export { default } from './ImageSSR';
7 changes: 4 additions & 3 deletions src/constants/componentMap.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import Image from 'next/image';
import { MDXComponents } from 'mdx/types';

import AboutMeToggleMessage from '@/components/AboutMeToggleMessage';
import { default as CodeSnippet } from '@/components/CodeSnippet/CodeSnippet';
import CV from '@/components/CurriculumVitae';
import FullWidthSplitSection from '@/components/FullWidthSplitSection';
import Image from '@/components/ImageSSR';
import ResponsiveImage from '@/components/ResponsiveImage';
import Spinner from '@/components/Spinner';
import TooltipMessage from '@/components/TooltipMessage';

export const COMPONENT_MAP = {
export const COMPONENT_MAP: MDXComponents = {
pre: CodeSnippet,
ResponsiveImage,
Image,
FullWidthSplitSection,
Spinner,
AboutMeToggleMessage,
TooltipMessage,
CV,
FullWidthSplitSection,
};

0 comments on commit 72de330

Please sign in to comment.