Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

MockedProvider - Cannot read property 'registeredQueries' of undefined #2738

Closed
rosskevin opened this issue Jan 18, 2019 · 13 comments
Closed
Assignees
Labels

Comments

@rosskevin
Copy link
Contributor

rosskevin commented Jan 18, 2019

Intended outcome:
MockedProvider works in storybook(?) without error.

Actual outcome:

Cannot read property 'registeredQueries' of undefined
    TypeError: Cannot read property 'registeredQueries' of undefined
    at MockedProvider.push../node_modules/react-apollo/test-utils.js.MockedProvider.componentWillUnmount (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:672705:35)
    at callComponentWillUnmountWithTimer (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:692391:12)
    at HTMLUnknownElement.callCallback (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:676475:14)
    at Object.invokeGuardedCallbackDev (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:676525:16)
    at invokeGuardedCallback (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:676582:31)
    at safelyCallComponentWillUnmount (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:692398:5)
    at commitUnmount (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:692772:11)
    at commitNestedUnmounts (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:692803:5)
    at unmountHostComponents (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:693064:7)
    at commitDeletion (http://localhost:6016/vendors~main.92813365353641d68d2e.bundle.js:693116:5)

How to reproduce the issue:
On initial click on a story, everything is good. Switch to a different story- good. Switch back to the first story- boom.

This appears to be a race condition that is adjacent to what we saw in #2164 and @danilobuerger fixed in #2165. I have spotted a potential root cause - working on it and PR now.

Version

  • react-apollo@2.3.3
  • apollo-client@2.4.9
@rosskevin rosskevin self-assigned this Jan 18, 2019
@rosskevin rosskevin added the bug label Jan 18, 2019
@danilobuerger
Copy link
Contributor

This seems unrelated. scheduler was removed by @benjamn a few hours ago thus breaking here: apollographql/apollo-client@b4f0c8e

@rosskevin
Copy link
Contributor Author

rosskevin commented Jan 18, 2019

      console.log(
        '----------------------------hey I am in the right spot',
        this.state.client.queryManager,
      )
      var scheduler = this.state.client.queryManager.scheduler
      Object.keys(scheduler.registeredQueries).forEach(function(queryId) {
        scheduler.stopPollingQuery(queryId)
      })
      Object.keys(scheduler.intervalQueries).forEach(function(interval) {
        scheduler.fetchQueriesOnInterval(interval)
      })

storybook

hmmm...

@danilobuerger
Copy link
Contributor

As far as I can tell by skimming over the linked commit, it should now be in pollingInfoByQueryId

@rosskevin
Copy link
Contributor Author

Discussion summary from slack: this api was not intended to be public, should probably have been marked as private via typescript scope. @benjamn introduced a change in apollo-client and wants to change the implementation in MockedProvider.

benjamn added a commit to apollographql/apollo-client that referenced this issue Jan 18, 2019
This reverts commit d4f3346.

Although apollographql/react-apollo#2738
resulted immediately from the removal of the scheduler, similar problems
will almost certainly arise from privatizing client.queryManager.
@benjamn benjamn reopened this Jan 18, 2019
benjamn added a commit to apollographql/apollo-client that referenced this issue Jan 18, 2019
Inspired by apollographql/react-apollo#2738, it
should be possible to shut down an ApolloClient instance without making
assumptions about its implementation details.

This client.stop() method should also be useful for server-side rendering,
where you're supposed to create (and throw away) a new ApolloClient
instance for each request.

I'm not entirely sure this implementation cleans up everything that might
need to be cleaned up, but I am sure it's better than nothing.
@benjamn
Copy link
Member

benjamn commented Jan 19, 2019

This has been fixed as of apollo-client@2.4.11, though #2741 should prevent the problem from ever happening again.

@benjamn benjamn closed this as completed Jan 19, 2019
@stolinski
Copy link

I'm getting this error. I am not using registeredQueries anywhere in my code.

apollo-client@2.5.1

TypeError: Cannot read property 'registeredQueries' of undefined

      at MockedProvider.Object.<anonymous>.MockedProvider.componentWillUnmount (node_modules/react-apollo/test-utils.js:1074:35)
      at callComponentWillUnmountWithTimer (node_modules/react-dom/cjs/react-dom.development.js:17123:12)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:149:14)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:199:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:256:31)
      at safelyCallComponentWillUnmount (node_modules/react-dom/cjs/react-dom.development.js:17130:5)
      at commitUnmount (node_modules/react-dom/cjs/react-dom.development.js:17507:11)
      at unmountHostComponents (node_modules/react-dom/cjs/react-dom.development.js:17827:7)
      at commitDeletion (node_modules/react-dom/cjs/react-dom.development.js:17858:5)
      at commitAllHostEffects (node_modules/react-dom/cjs/react-dom.development.js:18639:11)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:149:14)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:199:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:256:31)
      at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:18867:7)
      at node_modules/react-dom/cjs/react-dom.development.js:20372:5
      at Object.unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:255:12)
      at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:20371:13)
      at performWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:20300:9)
      at performWork (node_modules/react-dom/cjs/react-dom.development.js:20208:7)
      at performSyncWork (node_modules/react-dom/cjs/react-dom.development.js:20182:3)
      at requestWork (node_modules/react-dom/cjs/react-dom.development.js:20051:5)
      at scheduleWork (node_modules/react-dom/cjs/react-dom.development.js:19865:5)
      at scheduleRootUpdate (node_modules/react-dom/cjs/react-dom.development.js:20526:3)
      at updateContainerAtExpirationTime (node_modules/react-dom/cjs/react-dom.development.js:20554:10)
      at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:20611:10)
      at ReactRoot.Object.<anonymous>.ReactRoot.render (node_modules/react-dom/cjs/react-dom.development.js:20907:3)
      at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:21059:12)
      at node_modules/react-dom/cjs/react-dom.development.js:21132:9
      at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:20413:10)
      at Object.unmountComponentAtNode (node_modules/react-dom/cjs/react-dom.development.js:21131:7)
      at cleanupAtContainer (node_modules/react-testing-library/dist/index.js:146:21)
          at Set.forEach (<anonymous>)
      at Object.cleanup (node_modules/react-testing-library/dist/index.js:136:21)

@rosskevin
Copy link
Contributor Author

@stolinski you need to update your version of react-apollo.

@stolinski
Copy link

@rosskevin ah, gotcha. I was thinking 2.5.1 was the latest. That seemed to have done it. Thanks!

@ashoksudani
Copy link

ashoksudani commented Apr 2, 2019

@rosskevin, @stolinski : just for your information:
I have started facing similar issue considering cleanup but at different line of code : #2165 (comment)
I have tried different versions of react-apollo : 2.5.2 , 2.5.3 .. till 2.4.0
But it is working completely all right with from 2.3.3 or 2.1.8 :)

@sopranolinist
Copy link

sopranolinist commented Aug 19, 2019

@rosskevin, @stolinski : just for your information:
I have started facing similar issue considering cleanup but at different line of code : #2165 (comment)
I have tried different versions of react-apollo : 2.5.2 , 2.5.3 .. till 2.4.0
But it is working completely all right with from 2.3.3 or 2.1.8 :)

@rosskevin, @stolinski - I'm getting the exact same error described by @ashoksudani. Was using 2.5.8, and only rolling back to 2.3.3 or removing all instances of afterEach(cleanup) made the error go away. Wondering if you've run into anyone else with this issue? (PS I'm also using apollo-client 2.4.6)

@rtymchyk
Copy link

Issue occurs with apollo-client@2.63 and react-apollo@2.3.3

@rtymchyk
Copy link

Sorry, forgot to mention the most important part - it goes away with react-apollo@2.4.0 which supports ApolloClient#stop

@kakadiadarpan
Copy link

kakadiadarpan commented Dec 3, 2019

This issue also occurs with apollo-client v2.6.4 and react-apollo v2.5.8

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

No branches or pull requests

8 participants