React-apollo: MockedProvider - Cannot read property 'registeredQueries' of undefined

Created on 18 Jan 2019  路  13Comments  路  Source: apollographql/react-apollo

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

bug

All 13 comments

This seems unrelated. scheduler was removed by @benjamn a few hours ago thus breaking here: https://github.com/apollographql/apollo-client/commit/b4f0c8ea6c7564d8762b663903847919a6d37105

      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...

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

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.

This has been fixed as of [email protected], though https://github.com/apollographql/react-apollo/pull/2741 should prevent the problem from ever happening again.

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

[email protected]

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)

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

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

@rosskevin, @stolinski : just for your information:
I have started facing similar issue considering cleanup but at different line of code : https://github.com/apollographql/react-apollo/pull/2165#issuecomment-478865830
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 : 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)

Issue occurs with [email protected] and [email protected]

Sorry, forgot to mention the most important part - it goes away with [email protected] which supports ApolloClient#stop

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

Was this page helpful?
0 / 5 - 0 ratings