-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New docs #4181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New docs #4181
Conversation
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub. |
|
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. |
| import { emotions } from "./emotions"; | ||
|
|
||
| const protocol = process.env.NODE_ENV === "production" ? "https" : "http"; | ||
| const baseUrl = `${protocol}://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`; |
There was a problem hiding this comment.
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:
- Clone the repository
- Run
npm install && npm run devin thedocsdirectory without settingNEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URLin.env.local - Open the docs site and submit feedback - the URL sent to the feedback service will be malformed
- Check RSS feed at
/[lang]/rss.xml- feed links will contain "undefined" - 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.
There was a problem hiding this 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:
- MDN: String.prototype.replace() - "To perform a global search and replace, use a regular expression with the g flag, or use replaceAll() instead."
- Best Practice Article - Identifies this pattern as a common pitfall and anti-pattern

No description provided.