Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/routes/demos/12-mini-game/interface/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import useGame from "../use-game";

import styles from "./styles.module.css";

import { EnvConfig } from "~/utils/env";

export function Interface() {

const timeRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -61,7 +63,7 @@ export function Interface() {
</div>
<div className={styles["beta-version"]}>
<h3>New Version</h3>
<p>You can try <a href="https://three-js-react-bm4577zd6-gianzambonis-projects.vercel.app/demos/mini-game" target="_blank" rel="noopener noreferrer">new beta version 2 here</a>. But beware, it's in progress, so it might not be perfect yet.</p>
<p>You can try <a href={`${EnvConfig.next_version}/demos/mini-game`} target="_blank" rel="noopener noreferrer">new beta version 2 here</a>. But beware, it's in progress, so it might not be perfect yet.</p>
</div>
</div>;
}
9 changes: 9 additions & 0 deletions app/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_NEXT_VERSION: string
}

interface ImportMeta {
readonly env: ImportMetaEnv
}
9 changes: 9 additions & 0 deletions app/utils/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Environment configuration with proper typing
*/
export class EnvConfig {
static get next_version(): string {
console.log(import.meta.env);
return import.meta.env.VITE_NEXT_VERSION;
Comment on lines +5 to +7
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -name "env.ts" -type f | head -20

Repository: gianzamboni/three-js-react

Length of output: 88


🏁 Script executed:

cat -n app/utils/env.ts

Repository: gianzamboni/three-js-react

Length of output: 337


🏁 Script executed:

rg "next_version" --type ts --type js -B 2 -A 2

Repository: gianzamboni/three-js-react

Length of output: 859


🏁 Script executed:

rg "VITE_NEXT_VERSION" --type ts --type js -B 2 -A 2

Repository: gianzamboni/three-js-react

Length of output: 443


Validate VITE_NEXT_VERSION and remove env logging from the getter.

Line 6 logs the full env object in a hot path, and Line 7 assumes the variable is always present. The env var is used to construct URLs (e.g., in 12-mini-game interface); if missing, this produces undefined/demos/mini-game.

Proposed fix
 export class EnvConfig {
   static get next_version(): string {
-    console.log(import.meta.env);
-    return import.meta.env.VITE_NEXT_VERSION;
+    const baseUrl = import.meta.env.VITE_NEXT_VERSION;
+    if (!baseUrl) {
+      throw new Error("Missing required env var: VITE_NEXT_VERSION");
+    }
+    return baseUrl.replace(/\/+$/, "");
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/utils/env.ts` around lines 5 - 7, Remove the console.log from the static
getter next_version and validate import.meta.env.VITE_NEXT_VERSION before
returning it; in the static get next_version method check for a non-empty string
and either return a safe default (e.g., "") or throw a clear error when
VITE_NEXT_VERSION is missing/invalid so callers (like the 12-mini-game URL
construction) don't get "undefined" in paths—update references to
import.meta.env.VITE_NEXT_VERSION inside next_version and ensure no env object
is logged.

}
}