zooniverse / markdownz

Markdown viewer and editor for the zooniverse
Apache License 2.0
2 stars 4 forks source link

Replace rehype with rehype-dom in the browser #242

Closed eatyourgreens closed 10 months ago

eatyourgreens commented 10 months ago

Use rehype-dom 5.0 (36k) as the Rehype processor in browsers, where Rehype can use DOM APIs to parse HTML.

In Node, require in the full rehype processor, which is ~240k.

This should give smaller, faster bundles for Markdown parsing in browsers.

mcbouslog commented 10 months ago

I'm still investigating, but I think these changes are causing the following issue when running PFE locally linked to this updated markdownz:

ERROR in ../markdownz/node_modules/hast-util-from-dom/dist/hast-util-from-dom.mjs 2:0-32
Module not found: Error: Can't resolve 'hastscript/html' in '/Users/markbouslog/zooniverse/markdownz/node_modules/hast-util-from-dom/dist'
Did you mean 'html.js'?
BREAKING CHANGE: The request 'hastscript/html' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
Did you miss the leading dot in 'resolve.extensions'? Did you mean '[".*",".js",".jsx",".json",".cjsx",".coffee",".styl",".css"]' instead of '["*",".js",".jsx",".json",".cjsx",".coffee",".styl",".css"]'?
mcbouslog commented 10 months ago

I think rehype-dom should be v6.0.0 and I'll update the import in utils.js to import { rehypeDom } from 'rehype-dom';

eatyourgreens commented 10 months ago

😳 I tested it by installing it in @zooniverse/react-components then building and running the Next.js apps. I assumed it would work with the PFE webpack build if it also worked in the monorepo.

v6 is ESM only so can't be used here. Or at least, removing the CJS build from markdownz would then break PFE and the monorepo.