From a186dc4d3f79e68472a168518087d378c978e831 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 12 Aug 2024 14:42:31 +0300 Subject: [PATCH] vercel-edge-deploy-test --- app.config.ts | 2 +- src/routes/author/(all-authors).tsx | 13 +++++-------- src/routes/inbox/(chats).tsx | 12 +++++++++--- src/routes/inbox/[chat].tsx | 10 +++++++--- src/routes/topic/[slug]/[...tab].tsx | 11 +++++++---- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/app.config.ts b/app.config.ts index c68206fa..bd8a5af6 100644 --- a/app.config.ts +++ b/app.config.ts @@ -8,7 +8,7 @@ import sassDts from 'vite-plugin-sass-dts' const isVercel = Boolean(process?.env.VERCEL) const isNetlify = Boolean(process?.env.NETLIFY) const isBun = Boolean(process.env.BUN) -const runtime = isNetlify ? 'netlify' : isVercel ? 'vercel' : isBun ? 'bun' : 'node' +const runtime = isNetlify ? 'netlify' : isVercel ? 'vercel_edge' : isBun ? 'bun' : 'node' console.info(`[app.config] build for ${runtime}!`) const polyfillOptions = { diff --git a/src/routes/author/(all-authors).tsx b/src/routes/author/(all-authors).tsx index 92cd7130..b861f755 100644 --- a/src/routes/author/(all-authors).tsx +++ b/src/routes/author/(all-authors).tsx @@ -15,17 +15,13 @@ const fetchAuthorsWithStat = async (offset = 0, order?: string) => { return await authorsFetcher() } -export const fetchAllAuthors = async () => { - const authorsAllFetcher = loadAuthorsAll() - return await authorsAllFetcher() -} - export const route = { load: async ({ location: { query } }: RouteLoadFuncArgs) => { const by = query.by const isAll = !by || by === 'name' + const authorsAllFetcher = loadAuthorsAll() return { - authors: isAll && (await fetchAllAuthors()), + authors: isAll && (await authorsAllFetcher()), authorsByFollowers: await fetchAuthorsWithStat(10, 'followers'), authorsByShouts: await fetchAuthorsWithStat(10, 'shouts') } as AllAuthorsData @@ -38,13 +34,14 @@ type AllAuthorsData = { authors: Author[]; authorsByFollowers: Author[]; authors export default function AllAuthorsPage(props: RouteSectionProps) { const { t } = useLocalize() - const { addAuthors } = useAuthors() + const { addAuthors, authorsSorted } = useAuthors() // async load data: from ssr or fetch const data = createAsync(async () => { if (props.data) return props.data + const authorsAllFetcher = loadAuthorsAll() return { - authors: await fetchAllAuthors(), + authors: authorsSorted() || await authorsAllFetcher(), authorsByFollowers: await fetchAuthorsWithStat(10, 'followers'), authorsByShouts: await fetchAuthorsWithStat(10, 'shouts') } as AllAuthorsData diff --git a/src/routes/inbox/(chats).tsx b/src/routes/inbox/(chats).tsx index 100ad8ec..a8066440 100644 --- a/src/routes/inbox/(chats).tsx +++ b/src/routes/inbox/(chats).tsx @@ -2,21 +2,27 @@ import { RouteDefinition, RouteSectionProps, createAsync } from '@solidjs/router import { InboxView } from '~/components/Views/Inbox/Inbox' import { PageLayout } from '~/components/_shared/PageLayout' import { ShowOnlyOnClient } from '~/components/_shared/ShowOnlyOnClient' +import { useAuthors } from '~/context/authors' import { useLocalize } from '~/context/localize' +import { loadAuthorsAll } from '~/graphql/api/public' import { Author } from '~/graphql/schema/core.gen' -import { fetchAllAuthors } from '../author/(all-authors)' export const route = { load: async () => { + const authorsAllFetcher = loadAuthorsAll() return { - authors: await fetchAllAuthors() + authors: await authorsAllFetcher() } } } satisfies RouteDefinition export const InboxPage = (props: RouteSectionProps<{ authors: Author[] }>) => { const { t } = useLocalize() - const authors = createAsync(async () => props.data.authors || (await fetchAllAuthors())) + const { authorsSorted } = useAuthors() + const authors = createAsync(async () => { + const authorsAllFetcher = loadAuthorsAll() + return props.data.authors || authorsSorted() || (await authorsAllFetcher()) + }) return ( diff --git a/src/routes/inbox/[chat].tsx b/src/routes/inbox/[chat].tsx index 521fd3ae..8c79ec46 100644 --- a/src/routes/inbox/[chat].tsx +++ b/src/routes/inbox/[chat].tsx @@ -6,14 +6,15 @@ import { ShowOnlyOnClient } from '~/components/_shared/ShowOnlyOnClient' import { useInbox } from '~/context/inbox' import { useLocalize } from '~/context/localize' import { useSession } from '~/context/session' +import { loadAuthorsAll } from '~/graphql/api/public' import { Chat } from '~/graphql/schema/chat.gen' import { Author } from '~/graphql/schema/core.gen' -import { fetchAllAuthors } from '../author/(all-authors)' export const route = { load: async () => { + const authorsAllFetcher = loadAuthorsAll() return { - authors: await fetchAllAuthors() + authors: await authorsAllFetcher() } } } satisfies RouteDefinition @@ -24,7 +25,10 @@ export const ChatPage = (props: RouteSectionProps<{ authors: Author[] }>) => { const { createChat, chats } = useInbox() const [chat, setChat] = createSignal() const { session } = useSession() - const authors = createAsync(async () => props.data.authors || (await fetchAllAuthors())) + const authors = createAsync(async () => { + const authorsAllFetcher = loadAuthorsAll() + return props.data.authors || (await authorsAllFetcher()) + }) onMount(async () => { if (params.id.includes('-')) { diff --git a/src/routes/topic/[slug]/[...tab].tsx b/src/routes/topic/[slug]/[...tab].tsx index d081204f..a2c2bb1e 100644 --- a/src/routes/topic/[slug]/[...tab].tsx +++ b/src/routes/topic/[slug]/[...tab].tsx @@ -38,14 +38,17 @@ export type TopicPageProps = { articles?: Shout[]; topics: Topic[]; authors?: Au export default function TopicPage(props: RouteSectionProps) { const { t } = useLocalize() - const { addTopics } = useTopics() + const { addTopics, sortedTopics } = useTopics() const [loadingError, setLoadingError] = createSignal(false) const topic = createAsync(async () => { try { - const ttt: Topic[] = props.data.topics || (await fetchAllTopics()) || [] - addTopics(ttt) - console.debug('[route.topic] all topics loaded') + let ttt: Topic[] = sortedTopics() + if (!ttt) { + ttt = props.data.topics || (await fetchAllTopics()) || [] + addTopics(ttt) + console.debug('[route.topic] all topics loaded') + } const t = ttt.find((x) => x.slug === props.params.slug) return t } catch (_error) {