mobxjs / mobx-react

React bindings for MobX
https://mobx.js.org/react-integration.html
MIT License
4.85k stars 350 forks source link

Can `mobx-react-lite` be added to `mobx-react` cdn resource? #879

Closed kingller closed 4 years ago

kingller commented 4 years ago

Intended outcome

Excepted: When use mobx-react as externals, it works well when mobx-react cdn resource was added to html as before.

Actual outcome

When I upgrade mobx-react from 5.4.4 to 6.2.2, and use it as externals with the cdn resource https://unpkg.com/mobx-react, an error happens

Uncaught TypeError: Cannot read property 'isUsingStaticRendering' of undefined

But it's OK when 5.4.4, and works well when use it as a module, not as an external.

I take a look at the mobx-react cdn source,

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('mobx'), require('react'), require('mobx-react-lite')) :
    typeof define === 'function' && define.amd ? define(['exports', 'mobx', 'react', 'mobx-react-lite'], factory) :
    (global = global || self, factory(global.mobxReact = {}, global.mobx, global.React, global.mobxReactLite));
}(this, (function (exports, mobx, React, mobxReactLite) { 'use strict';

I find mobx-react-lite is required, but when I install mobx-react, it is not required to be installed, it's just one dependency of mobx-react. Can mobx-react-lite be added to the CDN resource of mobx-react by default to keep same as use it as module, so that users don't need to pay attention to the dependency inside?

How to reproduce the issue

Versions

"mobx": "4.15.4",
"mobx-react": "6.2.2",
"react": "16.13.1",
"react-dom": "16.13.1",
danielkcz commented 4 years ago

That's a general pitfall of UMD (CDN) approach, you need to manually take care of dependencies.

For mobx-react-lite you should include https://unpkg.com/mobx-react-lite before mobx-react.

kingller commented 4 years ago

OK. thanks.