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

Cannot ready property 'readContext' of undefined #14575

Closed
kevinwolfcr opened this issue Jan 12, 2019 · 4 comments
Closed

Cannot ready property 'readContext' of undefined #14575

kevinwolfcr opened this issue Jan 12, 2019 · 4 comments
Assignees

Comments

@kevinwolfcr
Copy link

kevinwolfcr commented Jan 12, 2019

Do you want to request a feature or report a bug?
Report a bug

What is the current behavior?
react-cache is not working with Suspense.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox
https://codesandbox.io/s/3jw6y3ww6

What is the expected behavior?
To show the loading screen, or at least not to fail

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
react: 16.8.0-alpha.0
react-dom: 16.8.0-alpha.0
react-cache: 2.0.0-alpha.1

@498628255
Copy link

498628255 commented Jan 17, 2019

If you just want to run the program in the development env, you can modify the code in 'react-cache/cjs/react-cache.development.js' by yourself:
old:

var currentOwner = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;

function readContext(Context, observedBits) {
  var dispatcher = currentOwner.currentDispatcher;
  if (dispatcher === null) {
    throw new Error('react-cache: read and preload may only be called from within a '   "component's render. They are not supported in event handlers or "   'lifecycle methods.');
  }
  return dispatcher.readContext(Context, observedBits);
}

'currentOwner' is no use except in function readContext. so here is the new:

var currentDispatcher = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;

function readContext(Context, observedBits) {
  var dispatcher = currentDispatcher.current;
  if (dispatcher === null) {
    throw new Error('react-cache: read and preload may only be called from within a '   "component's render. They are not supported in event handlers or "   'lifecycle methods.');
  }
  return dispatcher.readContext(Context, observedBits);
}

And that work in my code.

@threepointone
Copy link
Contributor

Did you delete your codesandbox repro? Please add it so I can have a look. also, can you try with the newer alpha? (16.8.0-alpha.1)

@gaearon
Copy link
Collaborator

gaearon commented Jan 23, 2019

(This is expected to not work until we release an update to react-cache that uses the new dispatcher field)

@gaearon
Copy link
Collaborator

gaearon commented Feb 8, 2019

See #14780 (comment).

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

4 participants