Skip to content

Commit 661b58b

Browse files
committed
fix: support creator circular import
Signed-off-by: Innei <tukon479@gmail.com>
1 parent f68d142 commit 661b58b

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

apps/renderer/src/lib/parse-markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import remarkRehype from "remark-rehype"
1717
import { unified } from "unified"
1818
import { VFile } from "vfile"
1919

20-
import { MarkdownLink } from "~/components/ui/markdown/renderers"
20+
import { MarkdownLink } from "~/components/ui/markdown/renderers/MarkdownLink"
2121

2222
export interface RemarkOptions {
2323
components: Partial<Components>

apps/renderer/src/modules/claim/feed-claim-modal.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import { useCurrentModal } from "~/components/ui/modal"
1313
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs"
1414
import { useAuthQuery } from "~/hooks/common"
1515
import type { FeedModel } from "~/models"
16-
import { Queries } from "~/queries"
17-
import { useClaimFeedMutation } from "~/queries/feed"
16+
import { feed as feedQuery, useClaimFeedMutation } from "~/queries/feed"
1817
import { useFeedById } from "~/store/feed"
1918

2019
export const FeedClaimModalContent: FC<{
@@ -26,7 +25,7 @@ export const FeedClaimModalContent: FC<{
2625
data: claimMessage,
2726
isLoading,
2827
error,
29-
} = useAuthQuery(Queries.feed.claimMessage({ feedId }), {
28+
} = useAuthQuery(feedQuery.claimMessage({ feedId }), {
3029
enabled: !!feed,
3130
})
3231
const { setClickOutSideToDismiss } = useCurrentModal()

apps/renderer/src/modules/entry-content/components/SupportCreator.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useTranslation } from "react-i18next"
22

3+
import { useWhoami } from "~/atoms/user"
34
import { FeedIcon } from "~/components/feed-icon"
45
import { Button } from "~/components/ui/button"
56
import { Divider } from "~/components/ui/divider"
@@ -22,6 +23,7 @@ export const SupportCreator = ({ entryId }: { entryId: string }) => {
2223
})
2324
const openBoostModal = useBoostModal()
2425

26+
const isMyOwnedFeed = feed?.ownerUserId === useWhoami()?.id
2527
if (!feed || feed.type !== "feed") return null
2628

2729
return (
@@ -41,11 +43,17 @@ export const SupportCreator = ({ entryId }: { entryId: string }) => {
4143
)}
4244

4345
<div className="flex items-center gap-4">
44-
<Button className="text-base" onClick={() => openTipModal()}>
45-
<i className="i-mgc-power-outline mr-1.5 text-lg" />
46-
{t("entry_content.support_creator")}
47-
</Button>
48-
<Button variant="outline" className="text-base" onClick={() => openBoostModal(feed.id)}>
46+
{!isMyOwnedFeed && (
47+
<Button className="text-base" onClick={() => openTipModal()}>
48+
<i className="i-mgc-power-outline mr-1.5 text-lg" />
49+
{t("entry_content.support_creator")}
50+
</Button>
51+
)}
52+
<Button
53+
variant={!isMyOwnedFeed ? "outline" : "primary"}
54+
className="text-base"
55+
onClick={() => openBoostModal(feed.id)}
56+
>
4957
<i className="i-mgc-rocket-cute-fi mr-1.5 text-lg" />
5058
{t("boost.boost_feed")}
5159
</Button>

configs/vite.render.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import react from "@vitejs/plugin-react"
77
import { prerelease } from "semver"
88
import type { UserConfig } from "vite"
99

10+
import { circularImportRefreshPlugin } from "../plugins/vite/hmr"
1011
import { customI18nHmrPlugin } from "../plugins/vite/i18n-hmr"
1112
import { localesPlugin } from "../plugins/vite/locales"
1213
import { twMacro } from "../plugins/vite/tw-macro"
@@ -31,6 +32,7 @@ export const viteRenderBaseConfig = {
3132

3233
plugins: [
3334
react(),
35+
circularImportRefreshPlugin(),
3436

3537
sentryVitePlugin({
3638
org: "follow-rg",

plugins/vite/hmr.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { HmrContext, Plugin } from "vite"
2+
3+
function hasCircularDependency(mod: any, server: any, visited = new Set()): boolean {
4+
if (visited.has(mod.id)) return true
5+
visited.add(mod.id)
6+
7+
const importers = server.moduleGraph.getModulesByFile(mod.file) || new Set()
8+
for (const importer of importers) {
9+
if (hasCircularDependency(importer, server, new Set(visited))) {
10+
return true
11+
}
12+
}
13+
14+
return false
15+
}
16+
17+
export const circularImportRefreshPlugin = (): Plugin => ({
18+
name: "circular-import-refresh",
19+
handleHotUpdate({ file, server }: HmrContext) {
20+
if (file.includes("store")) {
21+
const mod = server.moduleGraph.getModuleById(file)
22+
if (mod && hasCircularDependency(mod, server)) {
23+
console.warn(`Circular dependency detected in ${file}. Performing full page refresh.`)
24+
server.ws.send({ type: "full-reload" })
25+
return []
26+
}
27+
}
28+
},
29+
})

0 commit comments

Comments
 (0)