1
- import { Box , BoxProps , THEME , useDidMount } from "@artsy/palette"
1
+ import { Box , BoxProps , THEME } from "@artsy/palette"
2
2
import { themeGet } from "@styled-system/theme-get"
3
- import { FC } from "react"
3
+ import { FC , useEffect , useState } from "react"
4
4
import styled from "styled-components"
5
- import reactHtmlParser from "@artsy/react-html-parser"
6
5
import { ArticleTooltip , isSupportedArticleTooltip } from "./ArticleTooltip"
7
6
import { toStyle } from "Utils/toStyle"
8
7
@@ -11,8 +10,6 @@ interface ArticleHTMLProps extends BoxProps {
11
10
}
12
11
13
12
export const ArticleHTML : FC < ArticleHTMLProps > = ( { children, ...rest } ) => {
14
- const isMounted = useDidMount ( )
15
-
16
13
// Looks for links and if they are internal and a supported entity type,
17
14
// inserts the relevant tooltip.
18
15
const transform = ( node : Element , i : number ) => {
@@ -45,12 +42,17 @@ export const ArticleHTML: FC<ArticleHTMLProps> = ({ children, ...rest }) => {
45
42
}
46
43
}
47
44
48
- if ( isMounted ) {
49
- return (
50
- < Container { ...rest } >
51
- { reactHtmlParser ( children , { transform } ) }
52
- </ Container >
53
- )
45
+ const [ transformed , setTransformed ] = useState < string | null > ( null )
46
+
47
+ useEffect ( ( ) => {
48
+ // Relies on the DOMParser global being available in the browser.
49
+ import ( "@artsy/react-html-parser" ) . then ( ( { default : reactHtmlParser } ) => {
50
+ setTransformed ( reactHtmlParser ( children , { transform } ) )
51
+ } )
52
+ } , [ children ] )
53
+
54
+ if ( transformed ) {
55
+ return < Container { ...rest } > { transformed } </ Container >
54
56
}
55
57
56
58
return < Container dangerouslySetInnerHTML = { { __html : children } } { ...rest } />
0 commit comments