@lobehub/chat 0.71.0 → 0.71.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/package.json +1 -1
- package/src/layout/AppMobileLayout.tsx +0 -5
- package/src/pages/chat/index.page.tsx +8 -0
- package/src/store/session/hooks/index.ts +1 -0
- package/src/store/session/hooks/useEffectAfterHydrated.ts +22 -0
- package/src/store/session/hooks/useOnFinishHydrationSession.ts +2 -6
- package/src/store/session/hooks/useSessionHydrated.ts +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.71.1](https://github.com/lobehub/lobe-chat/compare/v0.71.0...v0.71.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-09-09**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Fix mobile route.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Fix mobile route, closes [#165](https://github.com/lobehub/lobe-chat/issues/165) ([d5e03b6](https://github.com/lobehub/lobe-chat/commit/d5e03b6))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 0.71.0](https://github.com/lobehub/lobe-chat/compare/v0.70.4...v0.71.0)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-09-09**</sup>
|
package/package.json
CHANGED
|
@@ -6,7 +6,6 @@ import { Flexbox } from 'react-layout-kit';
|
|
|
6
6
|
|
|
7
7
|
import SafeSpacing from '@/components/SafeSpacing';
|
|
8
8
|
import MobileTabBar from '@/features/MobileTabBar';
|
|
9
|
-
import { useOnFinishHydrationSession, useSessionStore } from '@/store/session';
|
|
10
9
|
|
|
11
10
|
const useStyles = createStyles(({ css, cx, stylish }) => ({
|
|
12
11
|
container: cx(
|
|
@@ -49,10 +48,6 @@ const AppMobileLayout = memo<AppMobileLayoutProps>(
|
|
|
49
48
|
({ children, showTabBar, navBar, style, className }) => {
|
|
50
49
|
const { styles, cx } = useStyles();
|
|
51
50
|
|
|
52
|
-
useOnFinishHydrationSession(() => {
|
|
53
|
-
useSessionStore.setState({ isMobile: true });
|
|
54
|
-
}, []);
|
|
55
|
-
|
|
56
51
|
return (
|
|
57
52
|
<>
|
|
58
53
|
<Head>
|
|
@@ -4,6 +4,7 @@ import { memo } from 'react';
|
|
|
4
4
|
import { Flexbox } from 'react-layout-kit';
|
|
5
5
|
|
|
6
6
|
import { useSessionStore } from '@/store/session';
|
|
7
|
+
import { useEffectAfterSessionHydrated } from '@/store/session/hooks';
|
|
7
8
|
import { agentSelectors } from '@/store/session/selectors';
|
|
8
9
|
import { genSiteHeadTitle } from '@/utils/genSiteHeadTitle';
|
|
9
10
|
|
|
@@ -22,6 +23,13 @@ const Chat = memo(() => {
|
|
|
22
23
|
const pageTitle = genSiteHeadTitle([avatar, title].filter(Boolean).join(' '));
|
|
23
24
|
const RenderLayout = mobile ? MobileLayout : DesktopLayout;
|
|
24
25
|
|
|
26
|
+
useEffectAfterSessionHydrated(
|
|
27
|
+
(store) => {
|
|
28
|
+
store.setState({ isMobile: mobile });
|
|
29
|
+
},
|
|
30
|
+
[mobile],
|
|
31
|
+
);
|
|
32
|
+
|
|
25
33
|
return (
|
|
26
34
|
<>
|
|
27
35
|
<Head>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useSessionStore } from '../store';
|
|
4
|
+
|
|
5
|
+
export const useEffectAfterSessionHydrated = (
|
|
6
|
+
fn: (session: typeof useSessionStore) => void,
|
|
7
|
+
deps: any[] = [],
|
|
8
|
+
) => {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const hasRehydrated = useSessionStore.persist.hasHydrated();
|
|
11
|
+
|
|
12
|
+
if (hasRehydrated) {
|
|
13
|
+
// 等价 useEffect 多次触发
|
|
14
|
+
fn(useSessionStore);
|
|
15
|
+
} else {
|
|
16
|
+
// 等价于 useEffect 第一次触发
|
|
17
|
+
useSessionStore.persist.onFinishHydration(() => {
|
|
18
|
+
fn(useSessionStore);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}, deps);
|
|
22
|
+
};
|
|
@@ -5,16 +5,12 @@ import { SessionStore, useSessionStore } from '../store';
|
|
|
5
5
|
/**
|
|
6
6
|
* 当 Session 水合完毕后才会执行的 useEffect
|
|
7
7
|
* @param fn
|
|
8
|
-
* @param deps
|
|
9
8
|
*/
|
|
10
|
-
export const useOnFinishHydrationSession = (
|
|
11
|
-
fn: (state: SessionStore) => void,
|
|
12
|
-
deps: any[] = [],
|
|
13
|
-
) => {
|
|
9
|
+
export const useOnFinishHydrationSession = (fn: (state: SessionStore) => void) => {
|
|
14
10
|
useEffect(() => {
|
|
15
11
|
// 只有当水合完毕后再开始做操作
|
|
16
12
|
useSessionStore.persist.onFinishHydration(() => {
|
|
17
13
|
fn(useSessionStore.getState());
|
|
18
14
|
});
|
|
19
|
-
},
|
|
15
|
+
}, []);
|
|
20
16
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useSessionStore } from '../store';
|
|
4
|
+
import { useOnFinishHydrationSession } from './useOnFinishHydrationSession';
|
|
4
5
|
|
|
5
6
|
export const useSessionHydrated = () => {
|
|
6
7
|
// 根据 sessions 是否有值来判断是否已经初始化
|
|
@@ -8,11 +9,9 @@ export const useSessionHydrated = () => {
|
|
|
8
9
|
|
|
9
10
|
const [isInit, setInit] = useState(hasInited);
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
15
|
-
}, []);
|
|
12
|
+
useOnFinishHydrationSession(() => {
|
|
13
|
+
if (!isInit) setInit(true);
|
|
14
|
+
});
|
|
16
15
|
|
|
17
16
|
return isInit;
|
|
18
17
|
};
|