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

Window and document not defined in Webworker #130

Closed
alizeaiter opened this issue Nov 6, 2019 · 3 comments
Closed

Window and document not defined in Webworker #130

alizeaiter opened this issue Nov 6, 2019 · 3 comments
Labels
question Further information is requested

Comments

@alizeaiter
Copy link

When using html-react-parser in Webworkers, window and document are not defined. You mentioned that it works also on Nodejs where window and dom are also not defined. How would one work around this.Thanks

@remarkablemark
Copy link
Owner

Great question @alizeaiter

The reason html-react-parser can be used in Node.js and in the browser is because of the dependency html-dom-parser, which is used to parse HTML string to DOM nodes.

In Node.js, html-dom-parser relies on htmlparser2; in the browser, html-dom-parser relies on the native browser API.

This is done to keep the bundle size small for the client. This is crucial because there is a direct correlation between bundle size and the time it takes to load it (as well as the cost it takes to serve it).

Now if you really wanted to include htmlparser2 in the html-dom-parser build, you'll need to remove the "browser" field and rebuild your bundle with webpack (or any other module bundler).

Otherwise, there should be other HTML to React parsers that can satisfy your needs.

I hope this answers your question.

@remarkablemark remarkablemark added the question Further information is requested label Nov 9, 2019
@alizeaiter
Copy link
Author

Thanks for your answer, I ended up using another parser that uses htmlparser2

@remarkablemark
Copy link
Owner

Sounds good! Closing the issue as it seems to be resolved.

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

No branches or pull requests

2 participants