Skip to content

Add support for edge environments like Vercel Edge, Cloudflare workers, etc #502

Closed
@dkokotov

Description

@dkokotov

Problem

When I tried to use this library (indirectly, via html-react-parser), I got the error: "Error: This browser does not support document.implementation.createHTMLDocument". I believe this is because the browser version of the library was being loaded instead of the server version.

This is basically same underlying issue as #181.

Suggested Solution

Ideally the bundling would work correctly such that the server version would be selected automatically in edge environments.

Short of that, you could have an explicit server export, so eg one could do something like import parse from 'html-dom-parser/server' to force loading the server version. this would then need to be propagated to html-react-parser as well, so one could force that library to use the server version of this library.

Workarounds

I verified that the underlying htmlparser2 library works fine in edge environment, so my workaround for now is to use that directly to parse the html to DOM, manually unset the parent for the nodes, and then call domToReact from html-react-parser directly with the parsed dom nodes. This works fine and is simple, so this is not high urgency - but would be nice to have for others trying to use this library (or more likely html-react-parser) in edge environments.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions