Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dkokotov opened this issue Aug 24, 2023 · 2 comments
Closed
Assignees
Labels

Comments

@dkokotov
Copy link

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.

@dkokotov
Copy link
Author

I found this solution: remarkablemark/html-react-parser#736 (comment). So I don't need my custom workaround anymore.

@remarkablemark
Copy link
Owner

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants