浏览代码

fix: server side render trigger GitHub api rate limit (#685)

tags/0.3.13
Joel 2 年前
父节点
当前提交
6a564e2d5c
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 21 次插入11 次删除
  1. 21
    11
      web/app/components/header/github-star/index.tsx

+ 21
- 11
web/app/components/header/github-star/index.tsx 查看文件

@@ -1,3 +1,5 @@
'use client'
import React, { useEffect, useState } from 'react'
import { Github } from '@/app/components/base/icons/src/public/common'
import type { GithubRepo } from '@/models/common'

@@ -10,18 +12,26 @@ const getStar = async () => {
return res.json()
}

const GithubStar = async () => {
let githubRepo: GithubRepo = { stargazers_count: 0 }

if (process.env.NODE_ENV === 'development')
return null

try {
githubRepo = await getStar()
}
catch (e) {
const GithubStar = () => {
const [githubRepo, setGithubRepo] = useState<GithubRepo>({ stargazers_count: 6000 })
const [isFetched, setIsFetched] = useState(false)
useEffect(() => {
(async () => {
try {
if (process.env.NODE_ENV === 'development')
return

await setGithubRepo(await getStar())
setIsFetched(true)
}
catch (e) {

}
})()
}, [])

if (!isFetched)
return null
}

return (
<a

正在加载...
取消
保存