Skip to content

next version link into env variables#37

Open
gianzamboni wants to merge 1 commit intomainfrom
new-next-env
Open

next version link into env variables#37
gianzamboni wants to merge 1 commit intomainfrom
new-next-env

Conversation

@gianzamboni
Copy link
Owner

@gianzamboni gianzamboni commented Mar 2, 2026

Summary by CodeRabbit

  • Chores
    • Updated version link configuration to use environment variables for improved flexibility and maintainability.

@vercel
Copy link

vercel bot commented Mar 2, 2026

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

Project Deployment Actions Updated (UTC)
three-js-react Ready Ready Preview, Comment Mar 2, 2026 7:47pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

This PR introduces type-safe environment variable access for Vite-based configuration. It defines TypeScript types for VITE_NEXT_VERSION, creates an EnvConfig utility class to access this value, and replaces a hardcoded URL in the mini-game interface component with dynamic environment-based configuration.

Changes

Cohort / File(s) Summary
Environment Configuration Setup
app/types/env.d.ts, app/utils/env.ts
Adds TypeScript type definitions for Vite environment variables (ImportMetaEnv interface with VITE_NEXT_VERSION) and creates an EnvConfig class with a static getter to safely access the next version from import.meta.env.
Component Integration
app/routes/demos/12-mini-game/interface/index.tsx
Replaces hardcoded beta version URL with dynamic EnvConfig.next_version getter call in the New Version section.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • PR #32: Directly related—this PR updates the New Version link component to use EnvConfig.next_version, replacing the previously hardcoded beta URL.

Poem

🐰 A config, so clean, now flows from the sky,
No hardcoded links make the bunnies sigh,
With types that are safe and variables that shine,
The environment whispers, "All will be fine!" ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving a hardcoded version URL into environment variables for dynamic configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch new-next-env

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/routes/demos/12-mini-game/interface/index.tsx (1)

66-66: Build the link with URL instead of string concatenation.

Line 66 can produce malformed URLs depending on env formatting. Use new URL() for safer composition.

Proposed refactor
 export function Interface() {
+  const betaMiniGameUrl = new URL("/demos/mini-game", EnvConfig.next_version).toString();
   return <div className={styles.interface}>
@@
-      <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>
+      <p>You can try <a href={betaMiniGameUrl} 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>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/routes/demos/12-mini-game/interface/index.tsx` at line 66, Replace the
string-concatenated href that uses `${EnvConfig.next_version}/demos/mini-game`
with a safe URL composition using the URL API: construct new
URL('/demos/mini-game', EnvConfig.next_version) and use its href (or toString())
for the anchor's href; update the JSX in the component that renders this <a>
(the line referencing EnvConfig.next_version) so it builds the link via URL to
avoid malformed URLs when EnvConfig.next_version includes or omits trailing
slashes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/utils/env.ts`:
- Around line 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.

---

Nitpick comments:
In `@app/routes/demos/12-mini-game/interface/index.tsx`:
- Line 66: Replace the string-concatenated href that uses
`${EnvConfig.next_version}/demos/mini-game` with a safe URL composition using
the URL API: construct new URL('/demos/mini-game', EnvConfig.next_version) and
use its href (or toString()) for the anchor's href; update the JSX in the
component that renders this <a> (the line referencing EnvConfig.next_version) so
it builds the link via URL to avoid malformed URLs when EnvConfig.next_version
includes or omits trailing slashes.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee0ad3a and 889a51e.

📒 Files selected for processing (3)
  • app/routes/demos/12-mini-game/interface/index.tsx
  • app/types/env.d.ts
  • app/utils/env.ts

Comment on lines +5 to +7
static get next_version(): string {
console.log(import.meta.env);
return import.meta.env.VITE_NEXT_VERSION;
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.

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.

1 participant