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

fix(chat): fix ssr redux-observable errors (Issue #2753) #2802

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/chat/src/hooks/useTokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const useTokenizer = (tokenizer: DialAIEntityModel['tokenizer']) => {

useEffect(() => {
return () => encoding?.free();
}, []);
}, [encoding]);

const getTokensLength = useCallback(
(str: string) => {
Expand Down
38 changes: 9 additions & 29 deletions apps/chat/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { Action, Store, configureStore } from '@reduxjs/toolkit';
import { CurriedGetDefaultMiddleware } from '@reduxjs/toolkit/dist/getDefaultMiddleware';
import { Store, configureStore } from '@reduxjs/toolkit';

import {
Epic,
EpicMiddleware,
combineEpics,
createEpicMiddleware,
} from 'redux-observable';
import { Epic, combineEpics, createEpicMiddleware } from 'redux-observable';

import { AddonsEpics } from './addons/addons.epics';
import { addonsSlice } from './addons/addons.reducers';
Expand Down Expand Up @@ -78,45 +72,31 @@ const reducer = {
marketplace: marketplaceSlice.reducer,
codeEditor: codeEditorSlice.reducer,
};
const getMiddleware = (
//eslint-disable-next-line @typescript-eslint/no-explicit-any
epicMiddleware: EpicMiddleware<Action<any>, Action<any>, void, any>,
) => {
return (getDefaultMiddleware: CurriedGetDefaultMiddleware) => {
return getDefaultMiddleware({
thunk: false,
serializableCheck: false,
}).concat(epicMiddleware);
};
};

let store: Store;
export type AppStore = ReturnType<typeof createStore>;
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

export const createStore = (preloadedState: { settings: SettingsState }) => {
if (typeof window === 'undefined') {
const epicMiddleware = createEpicMiddleware();

const middleware = getMiddleware(epicMiddleware);
const localStore = configureStore({
return configureStore({
reducer,
preloadedState,
middleware,
});
epicMiddleware.run(rootEpic as unknown as Epic);

return localStore;
}

if (!store) {
const epicMiddleware = createEpicMiddleware();

const middleware = getMiddleware(epicMiddleware);
store = configureStore({
reducer,
preloadedState,
middleware,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
thunk: false,
serializableCheck: false,
}).concat(epicMiddleware),
});
epicMiddleware.run(rootEpic as unknown as Epic);
}
Expand Down
Loading