-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
[next.js] global plugins do not register before logic components #60
Comments
Hey, first, I'm not sure this is possible: import { createStore } from '../store'
let store = createStore()
import Users from '../components/Users' ES requires that all You may try to just use this to install the plugin without going through the store: import 'kea-thunk/install' of course running it before any call to This global vs local plugins thing is very recent, and while it works great in my own app (and |
Few more points:
|
so this update basically made me switch from adding the thunk plugin to every module containing Just adding the plugin globally in my store.js file doesn't work since when server rendering with next.js the store is created with the page component, which will always happen after imports I tried to import the store first and in the module create a store with the plugin but that didn't work ( though I didn't make sure why) At first I was not happy about the misdirection and having to call but then I guess it is better in the it makes it known that a plugin is enabling the thunk feature |
I think we can close this issue for now |
Hey, I'm not sure how But, logically... it should be possible to get it to work somehow. Perhaps injecting them to the webpack config's entry point? |
I'm satisfied with the current solution so I won't invest more in figuring it out next.js is not magical, the I could probably reach a recommendation after sometime (though I don't think it will include messing with the webpack configurations), as stated the current system works will for me when it becomes an issue it will be addressed |
Ok, closing the issue then. When you or anyone else has more to add, feel free to reopen. |
@amrdraz 's way works fine. |
I'm currently trying to integrate store.js const reducers = combineReducers({
kea: keaReducer('kea'),
concepts: keaReducer('concepts'),
})
const bindMiddleware = middleware => {
if (process.env.NODE_ENV !== 'production') {
const { composeWithDevTools } = require('redux-devtools-extension')
return composeWithDevTools(applyMiddleware(...middleware))
}
return applyMiddleware(...middleware)
}
const configureStore = (preloadedState = {}) => {
/**
* Activate Kea plugins with every context
*/
activatePlugin(sagaPlugin)
/**
* Recreate the stdChannel (saga middleware) with every context.
*/
const sagaMiddleware = createSagaMiddleware()
/**
* Since Next.js does server-side rendering, you are REQUIRED to pass
* `preloadedState` when creating the store.
*/
const store = createStore(reducers, preloadedState, bindMiddleware([sagaMiddleware]))
/**
* next-redux-saga depends on `sagaTask` being attached to the store.
* It is used to await the rootSaga task before sending results to the client.
*/
store.sagaTask = sagaMiddleware.run(keaSaga)
return store
} When requesting any page, the app is just hanging there.` @amrdraz or @mariusandra could you reopen the issue. I can also help in making this work if you just point me in the right direction. It's a critical feature for us, as we need SSR. |
Hello there,
so, after quite a bit of debugging I noticed that including plugins directly works
however registering plugins on the store level does not
upon inspection I noticed that the
kea
function is executed before the ActivatePlugins function is.This happens even if I call the store before importing the component for some reason 🤔
And once the logic is initialized the global plugin is never referred to later
in this case all actions declared in
thunks
never show up.so far I resolved this by simply directly including the plugin
any idea why?
my current proposed solutions are make global plugins run on already initialized logic
allways use plugins on the logic level (which I will do until a solution is presented)
in the mean time
I only figured out I can use plugins on the logic level by following by inspecting the code
would be nice if this is mentioned in the thunk plugin documentation
I realized later it's already mentioned in the kea function documentation but it's kinda not where I would have looked when faced with a problem related to a plugin
thank you for you time 😃
The text was updated successfully, but these errors were encountered: