reduxjs / react-redux

Official React bindings for Redux
https://react-redux.js.org
MIT License
23.39k stars 3.36k forks source link

Stop using globalThis #2053

Closed iowxy closed 1 year ago

iowxy commented 1 year ago

What version of React, ReactDOM/React Native, Redux, and React Redux are you using?

What is the current behavior?

globalThis is not defined

https://github.com/foca-js/foca/issues/40 https://github.com/NervJS/taro/issues/14082

According the documentation, keyword globalThis is disabled on alipay mini-program and polyfill is helpless, could you please replace it?

What is the expected behavior?

Replace globalThis

Which browser and OS are affected by this issue?

Chinese alipay mini-program

Did this work in previous versions of React Redux?

iowxy commented 1 year ago

The documentation is here: https://opendocs.alipay.com/mini/framework/implementation-detail

phryneas commented 1 year ago

globalThis is part of the ECMAScript standard since ECMAScript 2020 - and has been implemented in most runtimes well before that.

We are at an impasse here, if we want to access a global value: there are runtimes that only have window and other runtimes that have global or self - usually not all of them. globalThis has been added to address that.

It is sad to see that there are still runtimes out there that do not adhere to the standard - or in this case, if my chinese translator is correct, outright disable this feature on purpose.

If I read that correctly, they deliberately disable any kind of global access, which would explain why the polyfill is not working for you - but that also means that we could not fall back to window, global or self, since they also disabled all of those.
If I am honest, this is a ridiculous choice on their side. Is there any way you can define a global variable in that runtime?

phryneas commented 1 year ago

I guess we can in that case fall back to module scope, essentially going back to pre-8.1 behavior. See b37e57e9eb8981b03b92a09c58bd15664cb64a12 .

Could you please try if this build solves your problem and still works without anything breaking?

npm i https://pkg.csb.dev/reduxjs/react-redux/commit/b37e57e9/react-redux
phryneas commented 1 year ago

This should be solved in v8.1.2.