Skip to content

Commit ffe4f84

Browse files
authored
Merge pull request #14555 from artsy/remove-js-dom
chore: removes jsdom middleware
2 parents 5113297 + fb1a0af commit ffe4f84

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

src/Apps/Article/Components/ArticleHTML.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { Box, BoxProps, THEME, useDidMount } from "@artsy/palette"
1+
import { Box, BoxProps, THEME } from "@artsy/palette"
22
import { themeGet } from "@styled-system/theme-get"
3-
import { FC } from "react"
3+
import { FC, useEffect, useState } from "react"
44
import styled from "styled-components"
5-
import reactHtmlParser from "@artsy/react-html-parser"
65
import { ArticleTooltip, isSupportedArticleTooltip } from "./ArticleTooltip"
76
import { toStyle } from "Utils/toStyle"
87

@@ -11,8 +10,6 @@ interface ArticleHTMLProps extends BoxProps {
1110
}
1211

1312
export const ArticleHTML: FC<ArticleHTMLProps> = ({ children, ...rest }) => {
14-
const isMounted = useDidMount()
15-
1613
// Looks for links and if they are internal and a supported entity type,
1714
// inserts the relevant tooltip.
1815
const transform = (node: Element, i: number) => {
@@ -45,12 +42,17 @@ export const ArticleHTML: FC<ArticleHTMLProps> = ({ children, ...rest }) => {
4542
}
4643
}
4744

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>
5456
}
5557

5658
return <Container dangerouslySetInnerHTML={{ __html: children }} {...rest} />

src/Server/DOMParser.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/middleware.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// Required for @artsy/react-html-parser which is included by @artsy/reaction
2-
// TODO: Find a way to remove JSDOM from our server.
3-
import "./Server/DOMParser"
4-
51
// Setup sharify
62
// TODO: Export a function instead of loading on import.
73
import "./Server/setup_sharify"

0 commit comments

Comments
 (0)