Skip to content

Conversation

@haydenbleasel
Copy link
Member

No description provided.

@vercel
Copy link

vercel bot commented Nov 18, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
swr Error Error Dec 10, 2025 4:17pm
swr-2 Ready Ready Preview Comment Dec 10, 2025 4:17pm

@li-jia-nan
Copy link

image

The new SWR docs feel so polished and high-end. Amazing work !

@codesandbox-ci
Copy link

codesandbox-ci bot commented Dec 10, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@haydenbleasel haydenbleasel marked this pull request as ready for review December 10, 2025 00:58
import { emotions } from "./emotions";

const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
const baseUrl = `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL environment variable is used without a fallback, which will result in malformed URLs like http://undefined/... if the variable is not set during local development or in environments where it's not automatically configured.

View Details
📝 Patch Details
diff --git a/docs/app/[lang]/rss.xml/route.ts b/docs/app/[lang]/rss.xml/route.ts
index f0c7a9c..245d369 100644
--- a/docs/app/[lang]/rss.xml/route.ts
+++ b/docs/app/[lang]/rss.xml/route.ts
@@ -4,7 +4,7 @@ import { title } from "@/geistdocs";
 import { source } from "@/lib/geistdocs/source";
 
 const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
-const baseUrl = `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`;
+const baseUrl = `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL || "localhost:3000"}`;
 
 export const revalidate = false;
 
diff --git a/docs/app/actions/feedback/index.ts b/docs/app/actions/feedback/index.ts
index 058ed41..dcac6d6 100644
--- a/docs/app/actions/feedback/index.ts
+++ b/docs/app/actions/feedback/index.ts
@@ -5,7 +5,7 @@ import type { Feedback } from "@/components/geistdocs/feedback";
 import { emotions } from "./emotions";
 
 const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
-const baseUrl = `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`;
+const baseUrl = `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL || "localhost:3000"}`;
 
 export const sendFeedback = async (
   url: string,
diff --git a/docs/components/geistdocs/ask-ai.tsx b/docs/components/geistdocs/ask-ai.tsx
index 9fa85ae..fd77e00 100644
--- a/docs/components/geistdocs/ask-ai.tsx
+++ b/docs/components/geistdocs/ask-ai.tsx
@@ -13,7 +13,7 @@ export const AskAI = ({ href }: AskAIProps) => {
   const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
   const url = new URL(
     href,
-    `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`
+    `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL || "localhost:3000"}`
   ).toString();
   const query = `Read this page, I want to ask questions about it. ${url}`;
 
diff --git a/docs/components/geistdocs/chat.tsx b/docs/components/geistdocs/chat.tsx
index a0cfdee..65d3a00 100644
--- a/docs/components/geistdocs/chat.tsx
+++ b/docs/components/geistdocs/chat.tsx
@@ -266,7 +266,8 @@ const ChatInner = ({ basePath, suggestions }: ChatProps) => {
                           {
                             defaultOrigin:
                               process.env
-                                .NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL,
+                                .NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL ||
+                              "localhost:3000",
                           },
                         ],
                       ]}
diff --git a/docs/components/geistdocs/open-in-chat.tsx b/docs/components/geistdocs/open-in-chat.tsx
index 713a575..49844a5 100644
--- a/docs/components/geistdocs/open-in-chat.tsx
+++ b/docs/components/geistdocs/open-in-chat.tsx
@@ -20,7 +20,7 @@ export const OpenInChat = ({ href }: OpenInChatProps) => {
   const protocol = process.env.NODE_ENV === "production" ? "https" : "http";
   const url = new URL(
     href,
-    `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`
+    `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL || "localhost:3000"}`
   ).toString();
   const query = `Read this page, I want to ask questions about it. ${url}`;
 

Analysis

Malformed URLs with undefined environment variable in local development

What fails: Five files construct URLs using NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL without a fallback, resulting in malformed URLs like http://undefined/docs/page when the environment variable is undefined during local development.

Affected files:

  • docs/app/actions/feedback/index.ts (feedback service URLs)
  • docs/app/[lang]/rss.xml/route.ts (RSS feed URLs)
  • docs/components/geistdocs/ask-ai.tsx (AI chat reference URLs)
  • docs/components/geistdocs/open-in-chat.tsx (external chat tool reference URLs)
  • docs/components/geistdocs/chat.tsx (security header defaultOrigin)

How to reproduce:

  1. Clone the repository
  2. Run npm install && npm run dev in the docs directory without setting NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL in .env.local
  3. Open the docs site and submit feedback - the URL sent to the feedback service will be malformed
  4. Check RSS feed at /[lang]/rss.xml - feed links will contain "undefined"
  5. Try "Ask AI about this page" - the URL passed to the AI will be malformed

Result: Runtime behavior constructs URLs with string value "undefined" embedded, e.g. http://undefined/docs/getting-started. The Vercel environment variables documentation confirms that NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL is only automatically set on Vercel deployments and requires manual setup locally (via vercel pull or .env.local).

Expected: URLs should fall back to a sensible default for local development (localhost:3000) when the environment variable is not set, allowing feedback submission, RSS feeds, and AI references to work correctly during development.

Fix: Added || "localhost:3000" fallback to all five instances where NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL is used to construct URLs.

Copy link

@vercel vercel bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

The code uses .replace(" ", "") which only removes the first space, when it should use .replace(/ /g, "") to remove all spaces.

View Details
📝 Patch Details
diff --git a/docs/lib/geistdocs/db.ts b/docs/lib/geistdocs/db.ts
index ad859d3..dafecbe 100644
--- a/docs/lib/geistdocs/db.ts
+++ b/docs/lib/geistdocs/db.ts
@@ -11,7 +11,7 @@ class ChatDatabase extends Dexie {
   messages!: EntityTable<StoredMessage, "id">;
 
   constructor() {
-    super(title.replace(" ", "").toLocaleLowerCase());
+    super(title.replaceAll(" ", "").toLocaleLowerCase());
     this.version(1).stores({
       messages: "id, timestamp, sequence",
     });

Analysis

String.replace() only removes first space instead of all spaces in database name

What fails: ChatDatabase constructor uses String.replace(" ", "") to sanitize the database name, which only removes the first space. If the title variable contains multiple spaces, subsequent spaces remain in the database name.

How to reproduce:

// Current title: 'SWR Documentation' (works because it has only one space)
const title = "SWR Documentation";
title.replace(" ", "").toLocaleLowerCase();  // Returns: "swrdocumentation" ✓

// If title changes to have multiple spaces:
const title = "SWR  Documentation  Test";
title.replace(" ", "").toLocaleLowerCase();  // Returns: "swr documentation  test" ✗

Expected behavior: All spaces should be removed, not just the first one. The method should use either .replaceAll(" ", "") or .replace(/ /g, "") to ensure complete space removal.

References:

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants