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

react-to-print is incompatible with SystemJS (and ES modules) #300

Closed
joeldenning opened this issue Oct 16, 2020 · 1 comment
Closed

react-to-print is incompatible with SystemJS (and ES modules) #300

joeldenning opened this issue Oct 16, 2020 · 1 comment
Labels

Comments

@joeldenning
Copy link
Contributor

react-to-print assumes that the React object has Object.prototype as its prototype, since it calls React.hasOwnProperty() and the hasOwnProperty function only exists on the Object.prototype.

https://github.com/gregnb/react-to-print/blob/dab3e2224b526f57130615fb977c42359ff10317/src/index.tsx#L4-L5

However, this assumption is not true of ES modules, nor of SystemJS modules. The ES module spec says that ES modules must have a prototype of null, which means that they do not have the hasOwnProperty function available on them. This issue has been discussed and fixed in a variety of places, including the following links:

I help maintain SystemJS, and a user reported this error originally with us (see https://single-spa.slack.com/archives/C8R6U7MT7/p1602879935124300).

The following code sandbox shows how the react-to-print library dies if provided a React object without Object.prototype as the prototype: https://codesandbox.io/s/blissful-flower-wy5k7?file=/index.html

The fix in this case is to call Object.prototype.hasOwnProperty.call(React, 'useContext'). I'll submit a PR with that fix.

MatthewHerbst added a commit that referenced this issue Oct 17, 2020
Use Object.prototype.hasOwnProperty. Resolves #300.
@MatthewHerbst
Copy link
Owner

Learn something new every day! Published as v2.10.3, thank you 🎉

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