From dae36ebd0b6ccb122a92eff751b6cf70ef567455 Mon Sep 17 00:00:00 2001 From: skinmaker1345 Date: Sun, 13 Oct 2024 01:50:24 +0900 Subject: [PATCH] fix: build crashes upon rendering static pages --- pages/bots/index.tsx | 16 ++++++++++++++++ pages/index.tsx | 15 +++++++++++++++ pages/security.tsx | 9 +++++++++ pages/servers/index.tsx | 15 +++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/pages/bots/index.tsx b/pages/bots/index.tsx index 64721d9781..e44f6037e8 100644 --- a/pages/bots/index.tsx +++ b/pages/bots/index.tsx @@ -4,6 +4,7 @@ import dynamic from 'next/dynamic' import { Bot, List } from '@types' import * as Query from '@utils/Query' import LongButton from '@components/LongButton' +import { PHASE_PRODUCTION_BUILD } from 'next/constants' const Advertisement = dynamic(() => import('@components/Advertisement')) const ResponsiveGrid = dynamic(() => import('@components/ResponsiveGrid')) @@ -66,6 +67,21 @@ const Index: NextPage = ({ votes, newBots, trusted }) => { } export const getStaticProps = async () => { + if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) { + const list = { + totalPage: 1, + currentPage: 1, + data: [], + } + return { + props: { + votes: list, + newBots: list, + trusted: list, + }, + revalidate: 1, + } + } const votes = await Query.get.list.votes.load(1) const newBots = await Query.get.list.new.load(1) const trusted = await Query.get.list.trusted.load(1) diff --git a/pages/index.tsx b/pages/index.tsx index 6b7ba75755..8bf7ba4d65 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -3,6 +3,7 @@ import dynamic from 'next/dynamic' import { Bot, List, Server } from '@types' import * as Query from '@utils/Query' +import { PHASE_PRODUCTION_BUILD } from 'next/constants' const Advertisement = dynamic(() => import('@components/Advertisement')) const ResponsiveGrid = dynamic(() => import('@components/ResponsiveGrid')) @@ -50,6 +51,20 @@ const Index: NextPage = ({ bots, servers }) => { } export const getStaticProps = async () => { + if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) { + const list = { + totalPage: 1, + currentPage: 1, + data: [], + } + return { + props: { + bots: list, + servers: list, + }, + revalidate: 1, + } + } const bots = await Query.get.list.votes.load(1) const servers = await Query.get.serverList.votes.load(1) diff --git a/pages/security.tsx b/pages/security.tsx index 673840dd21..5cca4fbdac 100644 --- a/pages/security.tsx +++ b/pages/security.tsx @@ -4,6 +4,7 @@ import dynamic from 'next/dynamic' import { User } from '@types' import { BUG_REPORTERS, BUG_REPORT_GROUPS } from '@utils/Constants' import { get } from '@utils/Query' +import { PHASE_PRODUCTION_BUILD } from 'next/constants' const Docs = dynamic(() => import('@components/Docs')) const DiscordAvatar = dynamic(() => import('@components/DiscordAvatar')) @@ -88,6 +89,14 @@ const Security: NextPage = ({ bugReports }) => { } export const getStaticProps: GetStaticProps = async () => { + if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) { + return { + props: { + bugReports: [], + }, + revalidate: 1, + } + } return { props: { bugReports: await Promise.all(BUG_REPORTERS.map((u) => get.user.load(u))), diff --git a/pages/servers/index.tsx b/pages/servers/index.tsx index 531e4cfd82..80e3304948 100644 --- a/pages/servers/index.tsx +++ b/pages/servers/index.tsx @@ -3,6 +3,7 @@ import dynamic from 'next/dynamic' import { Server, List } from '@types' import * as Query from '@utils/Query' +import { PHASE_PRODUCTION_BUILD } from 'next/constants' const Advertisement = dynamic(() => import('@components/Advertisement')) const ResponsiveGrid = dynamic(() => import('@components/ResponsiveGrid')) @@ -48,6 +49,20 @@ const ServerIndex: NextPage = ({ votes, trusted }) => { } export const getStaticProps = async () => { + if (process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD) { + const list = { + totalPage: 1, + currentPage: 1, + data: [], + } + return { + props: { + votes: list, + trusted: list, + }, + revalidate: 1, + } + } const votes = await Query.get.serverList.votes.load(1) const trusted = await Query.get.serverList.trusted.load(1)