Skip to content

Commit

Permalink
fix(app): replace remark with react-markdown (#14942)
Browse files Browse the repository at this point in the history
Closes RQA-2587 and RQA-2566

After the vite migration, the app would crash any time the release notes markdown file needed parsing, because remark decides to invoke process.cwd() for some reason. Webpack can mock "process" out, but there's no 1:1 analogous solution with Vite.

Although there's probably some hacky way do accomplish the same thing, remark-react has been deprecated for over three years, so that's more incentive to migrate.

After testing a few options, react-markdown is relatively lightweight and properly overrides the markdown as desired (ie, no additional changes need to be made to the markdown for the refactor). It also doesn't have the same Vfile lib dependency that is the source of the "process" issue, so no more crashing when parsing release notes. It's also well-maintained, etc.
  • Loading branch information
mjhuff authored Apr 17, 2024
1 parent 68aa208 commit c096931
Show file tree
Hide file tree
Showing 4 changed files with 612 additions and 211 deletions.
3 changes: 1 addition & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"react-error-boundary": "^4.0.10",
"react-i18next": "13.5.0",
"react-intersection-observer": "^8.33.1",
"react-markdown": "9.0.1",
"react-redux": "8.1.2",
"react-router-dom": "5.3.4",
"react-select": "5.4.0",
Expand All @@ -57,8 +58,6 @@
"redux": "4.0.5",
"redux-observable": "1.1.0",
"redux-thunk": "2.3.0",
"remark": "9.0.0",
"remark-react": "4.0.3",
"reselect": "4.0.0",
"rxjs": "^6.5.1",
"semver": "5.5.0",
Expand Down
33 changes: 16 additions & 17 deletions app/src/molecules/ReleaseNotes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
import * as React from 'react'
import remark from 'remark'
import reactRenderer from 'remark-react'
import Markdown from 'react-markdown'

import { StyledText } from '@opentrons/components'

import styles from './styles.module.css'

export interface ReleaseNotesProps {
source?: string | null
}

// ToDo (kk:09/22/2023) This component should be updated in the future
// since the package we use hasn't been updated more than 2 years.
// Also the creator recommends users to replace remark-react with rehype-react.
const renderer = remark().use(reactRenderer, {
remarkReactComponents: {
div: React.Fragment,
h2: HeaderText,
ul: React.Fragment,
li: ParagraphText,
p: ParagraphText,
a: ExternalLink,
},
})

const DEFAULT_RELEASE_NOTES = 'We recommend upgrading to the latest version.'

export function ReleaseNotes(props: ReleaseNotesProps): JSX.Element {
Expand All @@ -29,7 +17,18 @@ export function ReleaseNotes(props: ReleaseNotesProps): JSX.Element {
return (
<div className={styles.release_notes}>
{source != null ? (
renderer.processSync(source).contents
<Markdown
components={{
div: undefined,
ul: undefined,
h2: HeaderText,
li: ParagraphText,
p: ParagraphText,
a: ExternalLink,
}}
>
{source}
</Markdown>
) : (
<p>{DEFAULT_RELEASE_NOTES}</p>
)}
Expand Down
11 changes: 0 additions & 11 deletions app/typings/remark.d.ts

This file was deleted.

Loading

0 comments on commit c096931

Please sign in to comment.