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

TypeError: Cannot read property 'getChildContext' of undefined when trying to switch to Preact existing project (with redux) #2069

Closed
adam4leos opened this issue Oct 30, 2019 · 11 comments

Comments

@adam4leos
Copy link

adam4leos commented Oct 30, 2019

Ahoy.

I am currently trying to switch existing project (react v16.8 + react-redux v7.1) to preact (trying v10) by using preact & preact/compat aliases in webpack config.
And encountering next problem on application start ->

TypeError: Cannot read property 'getChildContext' of undefined

caused by usage of Provider component (from react-redux).
Screenshot 2019-10-30 at 17 01 21

Code itself ->

import React from 'react';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';


export const createEntrypoint = (ApplicationComponent, { store, persistor, playerInstance }) => (
  <Provider store={store}>
    <PersistGate loading={null} persistor={persistor}>
      <ApplicationComponent playerInstance={playerInstance} />
    </PersistGate>
  </Provider>
);

Following to the preact-module code it says that Provider has an 'undefined' value as 'this' (create-context file, https://github.com/preactjs/preact/blob/master/src/create-context.js#L14).

Same code works well without Provider so can't figure out what is wrong. Demo from this repo, with redux Provider usage works as well.

Any information will be much appreciated.

@marvinhagemeister
Copy link
Member

iirc there was an issue with react-hot-loader rewriting things weirdly which broke context. Just a shot in the dark.

@ppozniak
Copy link

I can only add up that I am getting the same error without Redux. It's just freezing my tab.

@andrewiggins
Copy link
Member

@ppozniak are you using react-hot-loader too?

@ppozniak
Copy link

@ppozniak are you using react-hot-loader too?

Yes I do.

@andrewiggins
Copy link
Member

Hmm seems like react-hot-loader is the commonality here and cause of the issue.

@adam4leos
Copy link
Author

@andrewiggins @ppozniak @marvinhagemeister hmm, very interesting. I'll investigate this one further. Appreciate your answers here.

@adam4leos
Copy link
Author

adam4leos commented Nov 4, 2019

I can confirm that this issue caused by conflicts with react-hot-loader. Disabling react-hot-loader removes the problem.

I'll try to find out what exactly conflicting, and maybe create same issue for react-hot-loader.

@adam4leos
Copy link
Author

Meanwhile, it looks like if you want to use hotloader alias for react-dom (https://github.com/gaearon/react-hot-loader#hot-loaderreact-dom), you'd run into conflict with preact, where we want to set "react-dom": "preact/compat" alias. Anything I'm missing here, how this could be done better?

@LinusCenterstrom
Copy link

Having the same problem here, is there any workaround to get react-hot-loader to work with Preact?

@dangreen
Copy link

@marvinhagemeister gaearon/react-hot-loader#1445 (comment)

@marvinhagemeister
Copy link
Member

FYI: We're close to getting an official fast-refresh plugin for Preact out. It supports not just component HMR but also hooks. We'll announce it sometime in the coming weeks and need a bit of time to resolve remaining issues. This is doable without extending options like proposed in the react-hot-loader repo above.

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

No branches or pull requests

6 participants