Skip to content

Commit 397d835

Browse files
authored
fix: loading state and flickering issue (#490)
* Revert "fix(share): prevent same announcement display (#215)" This reverts commit a8e8bae. * fix: loading state and flickering issue
1 parent f6c59d5 commit 397d835

2 files changed

Lines changed: 9 additions & 15 deletions

File tree

src/app/MustUser.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import { r, handleResp, handleRespWithoutAuthAndNotify } from "~/utils"
77

88
const MustUser = (props: { children: JSXElement }) => {
99
const t = useT()
10-
const [loading, data] = useFetch((): PResp<Me> => r.get("/me"))
10+
const [loading, data] = useFetch((): PResp<Me> => r.get("/me"), true)
1111
const [err, setErr] = createSignal<string>()
12-
;(async () => {
13-
// const resp: Resp<User> = await data();
12+
onMount(async () => {
1413
handleResp(await data(), setMe, setErr)
15-
})()
14+
})
1615
return (
1716
<Switch fallback={props.children}>
1817
<Match when={loading()}>
@@ -26,7 +25,8 @@ const MustUser = (props: { children: JSXElement }) => {
2625
}
2726

2827
const UserOrGuest = (props: { children: JSXElement }) => {
29-
const [loading, data] = useFetch((): PResp<Me> => r.get("/me"))
28+
// 将loading默认设置为true,修复children被提前渲染,明显症状:两个公告
29+
const [loading, data] = useFetch((): PResp<Me> => r.get("/me"), true)
3030
const [skipLogin, setSkipLogin] = createSignal(false)
3131
onMount(async () => {
3232
handleRespWithoutAuthAndNotify(await data(), setMe, (_msg, _code) => {
@@ -40,6 +40,7 @@ const UserOrGuest = (props: { children: JSXElement }) => {
4040
permission: 0,
4141
sso_id: "",
4242
otp: false,
43+
allow_ldap: false,
4344
})
4445
setSkipLogin(true)
4546
})

src/pages/home/Layout.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@ import { Body } from "./Body"
66
import { Footer } from "./Footer"
77
import { Header } from "./header/Header"
88
import { Toolbar } from "./toolbar/Toolbar"
9-
import { onMount } from "solid-js"
10-
11-
let announcementShown = false
129

1310
const Index = () => {
1411
useTitle(getSetting("site_title"))
1512
const announcement = getSetting("announcement")
16-
17-
onMount(() => {
18-
if (announcement && !announcementShown) {
19-
notify.render(() => <Markdown children={announcement} />)
20-
announcementShown = true
21-
}
22-
})
13+
if (announcement) {
14+
notify.render(<Markdown children={announcement} />)
15+
}
2316
return (
2417
<>
2518
<Header />

0 commit comments

Comments
 (0)