mobxjs / mobx-react-lite

Lightweight React bindings for MobX based on React 16.8 and Hooks
https://mobx.js.org/react-integration.html
MIT License
2.13k stars 90 forks source link

Observer batching not working in electron or am I doing something wrong? #269

Closed barbalex closed 4 years ago

barbalex commented 4 years ago

Intended outcome

I updated mobx-react-lite from v1.5.2 to v2.0.0. Then after running yarn dev I saw a friendly message in the console and so added import 'mobx-react-lite/batchingForReactDom' to the index.js file.

Expected the app to work as before.

Actual outcome

After running yarn dev I got a blank screen and this error in the console:

batchingForReactDom.js:2 Uncaught TypeError: __webpack_require__(...).optimizeScheduler is not a function
    at Object../node_modules/mobx-react-lite/batchingForReactDom.js
    at __webpack_require__ (bootstrap:725)
    at fn (bootstrap:100)
    at Module../src/index.js (index.js:166548)
    at __webpack_require__ (bootstrap:725)
    at fn (bootstrap:100)
    at Object.0 (index.js:171528)
    at __webpack_require__ (bootstrap:725)
    at bootstrap:792
    at bootstrap:792

How to reproduce the issue

This is an electron project built with electron-forge. I am not sure how to build something helpful and reproducible.

Versions

Here is my package.json: https://github.com/barbalex/awel-personal/blob/master/package.json

danielkcz commented 4 years ago

Ouch, thanks for the report, small typo. It should be fixed in 2.0.1 I just published.

barbalex commented 4 years ago

Thanks @FredyC

v2.0.1 corrects the error. I have now added import 'mobx-react-lite/batchingForReactDom' to index.js (https://github.com/barbalex/awel-personal/blob/master/src/index.js#L4) and the app starts up correctly. But I am still getting the friendly message in the console:

[MobX] You haven't configured observer batching which might result in unexpected behavior in some cases. See more at https://github.com/mobxjs/mobx-react-lite/#observer-batching
danielkcz commented 4 years ago

@barbalex That's strange, I tried to reproduce here and it works correctly. Are you sure you don't have anything cached somewhere?

https://codesandbox.io/s/eloquent-clarke-2fzry

prymitive commented 4 years ago

Will that also be fixed in mobx-react? 6.2.0 throws same error.

danielkcz commented 4 years ago

@prymitive The mobx-react does not have a hard dependency on 2.0.0, so if you managed to install deps before 2.0.1 got out, you need to force the update I think. With Yarn it's yarn --force, not so sure about NPM.

akphi commented 4 years ago
[MobX] You haven't configured observer batching which might result in unexpected behavior in some cases. See more at https://github.com/mobxjs/mobx-react-lite/#observer-batching

@barbalex is your problem somehow related to #271 ? I use Typescript in my project so maybe that messes something up with the import statement (I have described my findings in the Research section)

barbalex commented 4 years ago

Well, to be honest, I have no idea what could mess with my import statements. This project was ported from electron-react-boilerplate to electron-forge. It uses webpack. But don't ask me what is going on under the hub 🙄

akphi commented 4 years ago

@barbalex well, @FredyC just released 2.0.2 which solved my problem so maybe you can try out now :)

barbalex commented 4 years ago

Yep, version 2.0.2 solved it for me too. Thanks you all! Especially @FredyC who seems to be involved in a whole bunch of interesting projects 👏