fix build bug

This commit is contained in:
AC 2025-06-11 15:43:43 +08:00
parent cd0366392a
commit f72aadc35d
7 changed files with 32 additions and 11 deletions

View File

@ -367,11 +367,13 @@ export function getClientApi(provider: ServiceProvider | string): ClientApi {
"| Type:", "| Type:",
typeof provider, typeof provider,
"| Browser:", "| Browser:",
navigator.userAgent.includes("Edge") typeof navigator !== "undefined"
? "Edge" ? navigator.userAgent.includes("Edge")
: navigator.userAgent.includes("Safari") ? "Edge"
? "Safari" : navigator.userAgent.includes("Safari")
: "Other", ? "Safari"
: "Other"
: "SSR",
); );
// Standardize the provider name to match Enum case (TitleCase) // Standardize the provider name to match Enum case (TitleCase)

View File

@ -967,7 +967,9 @@ export function DeleteImageButton(props: { deleteImage: () => void }) {
} }
export function ShortcutKeyModal(props: { onClose: () => void }) { export function ShortcutKeyModal(props: { onClose: () => void }) {
const isMac = navigator.platform.toUpperCase().indexOf("MAC") >= 0; const isMac =
typeof navigator !== "undefined" &&
navigator.platform.toUpperCase().indexOf("MAC") >= 0;
const shortcuts = [ const shortcuts = [
{ {
title: Locale.Chat.ShortcutKey.newChat, title: Locale.Chat.ShortcutKey.newChat,

View File

@ -97,6 +97,9 @@ function setItem(key: string, value: string) {
function getLanguage() { function getLanguage() {
try { try {
if (typeof navigator === "undefined") {
return DEFAULT_LANG;
}
const locale = new Intl.Locale(navigator.language).maximize(); const locale = new Intl.Locale(navigator.language).maximize();
const region = locale?.region?.toLowerCase(); const region = locale?.region?.toLowerCase();
// 1. check region code in ALL_LANGS // 1. check region code in ALL_LANGS

View File

@ -1,6 +1,13 @@
import { Analytics } from "@vercel/analytics/react"; import { Analytics } from "@vercel/analytics/react";
import { Home } from "./components/home";
import { getServerSideConfig } from "./config/server"; import { getServerSideConfig } from "./config/server";
import dynamic from "next/dynamic";
const Home = dynamic(
() => import("./components/home").then((mod) => ({ default: mod.Home })),
{
ssr: false,
},
);
const serverConfig = getServerSideConfig(); const serverConfig = getServerSideConfig();

View File

@ -492,7 +492,10 @@ export const useChatStore = createPersistStore(
); );
// Add detailed browser and session logging // Add detailed browser and session logging
console.log("[onUserInput] Browser:", navigator.userAgent); console.log(
"[onUserInput] Browser:",
typeof navigator !== "undefined" ? navigator.userAgent : "SSR",
);
console.log( console.log(
"[onUserInput] Full modelConfig:", "[onUserInput] Full modelConfig:",
JSON.stringify(modelConfig, null, 2), JSON.stringify(modelConfig, null, 2),

View File

@ -20,8 +20,8 @@ export function trimTopic(topic: string) {
return ( return (
topic topic
// fix for gemini // fix for gemini
.replace(/^["“”*]+|["“”*]+$/g, "") .replace(/^["""*]+|["""*]+$/g, "")
.replace(/[,。!?”“"、,.!?*]*$/, "") .replace(/[,。!?""""、,.!?*]*$/, "")
); );
} }
@ -114,6 +114,9 @@ export function readFromFile() {
} }
export function isIOS() { export function isIOS() {
if (typeof navigator === "undefined") {
return false;
}
const userAgent = navigator.userAgent.toLowerCase(); const userAgent = navigator.userAgent.toLowerCase();
return /iphone|ipad|ipod/.test(userAgent); return /iphone|ipad|ipod/.test(userAgent);
} }

View File

@ -69,7 +69,8 @@ export function fetch(url: string, options?: RequestInit): Promise<Response> {
const headers: Record<string, string> = { const headers: Record<string, string> = {
Accept: "application/json, text/plain, */*", Accept: "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7", "Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7",
"User-Agent": navigator.userAgent, "User-Agent":
typeof navigator !== "undefined" ? navigator.userAgent : "NextChat",
}; };
for (const item of new Headers(_headers || {})) { for (const item of new Headers(_headers || {})) {
headers[item[0]] = item[1]; headers[item[0]] = item[1];