iTwin / viewer-components-react

Components built on iTwin.js for usability in an iTwin.js based Viewer.
MIT License
24 stars 33 forks source link

[itwin-viewer-react] "Redux Store has not been initialized" if UiFramework initialized with custom store #74

Closed MichaelBelousov closed 3 years ago

MichaelBelousov commented 3 years ago

Maybe I'm doing something wrong here, but I am initializing UiFramework with a custom store instance, and as a result the Viewer component throws this error:

BentleyError.ts:400 Uncaught Error: Redux Store has not been initialized
    at Function.get store [as store] (StateManager.ts:89)
    at IModelLoader.tsx:247
    at renderWithHooks (react-dom.development.js:14803)
    at updateFunctionComponent (react-dom.development.js:17034)
    at updateSimpleMemoComponent (react-dom.development.js:16972)
    at beginWork (react-dom.development.js:18687)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at beginWork$1 (react-dom.development.js:23203)
    at performUnitOfWork (react-dom.development.js:22157)
    at workLoopSync (react-dom.development.js:22130)
    at performSyncWorkOnRoot (react-dom.development.js:21756)
    at react-dom.development.js:11089
    at unstable_runWithPriority (scheduler.development.js:653)
    at runWithPriority$1 (react-dom.development.js:11039)
    at flushSyncCallbackQueueImpl (react-dom.development.js:11084)
    at flushSyncCallbackQueue (react-dom.development.js:11072)
    at scheduleUpdateOnFiber (react-dom.development.js:21199)
    at dispatchAction (react-dom.development.js:15660)
    at getModelConnection (IModelLoader.tsx:161)

My cursory understanding is that itwin-viewer-react erroneously uses StateManager's store reference when it should be using UiFramework's store reference which allows both. Otherwise I don't know much about StateManager's role.

MichaelBelousov commented 3 years ago

I am going to attempt a (bad) workaround and report back if I succeed

MichaelBelousov commented 3 years ago

seems to work

await UiFramework.initialize(store, IModelApp.i18n);
// SEE: https://github.com/imodeljs/viewer-components-react/issues/74
(StateManager as any)._singletonStore = store;
aruniverse commented 3 years ago

Depending on what you're doing, i would argue this issue be filed with the itwin-viewer repo, not viewer-components-react

MichaelBelousov commented 3 years ago

I may have brain-hiccupped and thought that this monorepo contained that package. I'll make an identical issue there

MichaelBelousov commented 3 years ago

made https://github.com/imodeljs/itwin-viewer/issues/62, closing this one