Skip to content

Commit

Permalink
🐛 fix hydration error (#2289)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle authored May 8, 2024
1 parent c0402e9 commit c16d9b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 51 deletions.
2 changes: 1 addition & 1 deletion web/core/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
)

return (
<BaseLink className={classNames} ref={ref} href={href} {...rest}>
<BaseLink className={classNames} type={type} ref={ref} href={href} {...rest}>
{children}
{type === 'externalUrl' && <ArrowRight className="inline-block pt-1 -rotate-45 origin-bottom-left" />}
</BaseLink>
Expand Down
77 changes: 27 additions & 50 deletions web/pageComponents/shared/portableText/Blocks.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import {
defaultComponents,
PortableText,
PortableTextProps,
PortableTextReactComponents,
Expand All @@ -21,25 +20,31 @@ type TypeProps = {
children?: React.ReactNode
}

const defaultBlocks: BlockType = {
smallText: ({ children }: TypeProps) => <p className="text-sm">{children}</p>,
}

const defaultMarks: MarkType = {
sub: ({ children }: TypeProps) => <sub>{children}</sub>,
sup: ({ children }: TypeProps) => <sup>{children}</sup>,
s: ({ children }: TypeProps) => <s>{children}</s>,
link: ExternalLink,
internalLink: InternalLink,
}

const defaultTypes: TypesType = {
//@ts-ignore
positionedInlineImage: (props) => <FigureWithLayout {...props} />,
//@ts-ignore
pullQuote: (props) => <Quote {...props} className="not-prose" />,
//@ts-ignore
basicIframe: (props) => <BasicIframe {...props} className="not-prose px-layout-md" />,
const defaultSerializers = {
block: {
smallText: ({ children }: TypeProps) => <p className="text-sm">{children}</p>,
},
types: {
//@ts-ignore
positionedInlineImage: (props) => <FigureWithLayout {...props} />,
//@ts-ignore
pullQuote: (props) => <Quote {...props} className="not-prose" />,
//@ts-ignore
basicIframe: (props) => <BasicIframe {...props} className="not-prose px-layout-md" />,
},
marks: {
sub: ({ children }: TypeProps) => <sub>{children}</sub>,
sup: ({ children }: TypeProps) => <sup>{children}</sup>,
s: ({ children }: TypeProps) => <s>{children}</s>,
//TODO find proper type
link: ({ children, value }: any) => {
return <ExternalLink value={value}>{children}</ExternalLink>
},
//TODO find proper type
internalLink: ({ children, value }: any) => {
return <InternalLink value={value}>{children}</InternalLink>
},
},
}

type BlockProps = {
Expand Down Expand Up @@ -77,36 +82,9 @@ type BlockProps = {
const inlineBlockTypes = ['block', 'positionedInlineImage', 'pullQuote', 'basicIframe']

//@ts-ignore
export default function Blocks({
value,
blocks,
marks,
types,
components,
proseClassName = '',
className = '',
id,
}: BlockProps) {
export default function Blocks({ value, components, proseClassName = '', className = '', id }: BlockProps) {
let div: PortableTextBlock[] = []

const serializers: PortableTextReactComponents = {
...defaultComponents,
block: {
...defaultComponents.block,
...defaultBlocks,
...blocks,
} as BlockType,
marks: {
...defaultComponents.marks,
...defaultMarks,
...marks,
} as MarkType,
types: {
...defaultComponents.types,
...(types ?? defaultTypes),
} as TypesType,
}

return (
<>
{
Expand All @@ -129,7 +107,7 @@ export default function Blocks({
value={value}
//@ts-ignore
components={{
...serializers,
...defaultSerializers,
}}
/>
</div>
Expand Down Expand Up @@ -165,7 +143,6 @@ export default function Blocks({
key={block._key}
value={block}
components={{
...defaultComponents,
...components,
}}
/>
Expand Down

0 comments on commit c16d9b2

Please sign in to comment.