Skip to content

Conversation

@erickmmolina
Copy link

@erickmmolina erickmmolina commented May 22, 2025

Summary by CodeRabbit

  • New Features

    • Added new utility functions for environment detection, allowing the app to distinguish between development, production, test, and staging environments.
    • Introduced support for a new environment variable for more flexible runtime environment configuration.
  • Refactor

    • Centralized environment checks throughout the app to use new utility functions, improving consistency and maintainability.

@coderabbitai
Copy link

coderabbitai bot commented May 22, 2025

Walkthrough

Environment detection throughout the codebase is centralized by introducing utility functions in envUtils for determining the current runtime environment. Multiple files are updated to use these new utilities instead of directly checking environment variables. The environment schema is also extended to include a custom NEXT_PUBLIC_APP_ENV variable for more flexible environment management.

Changes

File(s) Change Summary
src/env.js Added envUtils with isDevelopment, isProduction, isTest, and isStaging functions. Extended the environment schema and runtime extraction to include NEXT_PUBLIC_APP_ENV.
src/app/api/trpc/[trpc]/route.ts
src/app/layout.tsx
src/components/onboarding/signin/index.tsx
src/trpc/react.tsx
Replaced direct environment variable checks with envUtils.isDevelopment() for environment detection. Updated imports to use the new utility.

Poem

In burrows deep where code does dwell,
A rabbit brings new tools as well!
With envUtils now in command,
Environments are close at hand.
No more guessing, no more mess—
Just hop along and use the best!
🐇🌱

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link

github-actions bot commented May 22, 2025

Hey @erickmmolina thank you for opening this pull request! 👋

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "Feature/env mode control". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@coderabbitai
Copy link

coderabbitai bot commented May 22, 2025

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] I see that there's an issue with the PR title not following the Conventional Commits specification. The current title "Feature/env mode control" needs to be prefixed with an appropriate type.

Based on the PR content, this appears to be adding a new feature, so the title should be changed to:

feat: env mode control

To update the PR title:

  1. Click on the "Edit" button (pencil icon) next to the current PR title
  2. Change it to follow the format: <type>[optional scope]: <description>
  3. Save the changes

This format helps with automated versioning and changelog generation. The Conventional Commits specification makes it easier to track what kind of changes are being made in each PR.

Hope this helps! Let me know if you need any further assistance.

ʕ •ᴥ•ʔ

Copy link

@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: 0

🧹 Nitpick comments (1)
src/env.js (1)

19-86: Environment detection utilities look solid, but could be more DRY

The implementation of utility functions for environment detection is a good approach for centralizing this logic. However, there's significant code duplication across the four functions that could be refactored.

Consider refactoring to use a single helper function:

-// Utility functions to check environment
-function isDevelopment() {
-  // First check the custom environment variable from runtime
-  if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) {
-    return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "development";
-  }
-  
-  // Then check process.env
-  if (process.env.NEXT_PUBLIC_APP_ENV) {
-    return process.env.NEXT_PUBLIC_APP_ENV === "development";
-  }
-  
-  // Fall back to NODE_ENV
-  return process.env.NODE_ENV === "development";
-}
-
-function isProduction() {
-  // First check the custom environment variable from runtime
-  if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) {
-    return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "production";
-  }
-  
-  // Then check process.env
-  if (process.env.NEXT_PUBLIC_APP_ENV) {
-    return process.env.NEXT_PUBLIC_APP_ENV === "production";
-  }
-  
-  // Fall back to NODE_ENV
-  return process.env.NODE_ENV === "production";
-}
-
-function isTest() {
-  // First check the custom environment variable from runtime
-  if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) {
-    return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "test";
-  }
-  
-  // Then check process.env
-  if (process.env.NEXT_PUBLIC_APP_ENV) {
-    return process.env.NEXT_PUBLIC_APP_ENV === "test";
-  }
-  
-  // Fall back to NODE_ENV
-  return process.env.NODE_ENV === "test";
-}
-
-function isStaging() {
-  // First check the custom environment variable from runtime
-  if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) {
-    return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === "staging";
-  }
-  
-  // Then check process.env
-  if (process.env.NEXT_PUBLIC_APP_ENV) {
-    return process.env.NEXT_PUBLIC_APP_ENV === "staging";
-  }
-  
-  // Fall back to NODE_ENV
-  return process.env.NODE_ENV === "staging";
-}
+// Helper function to check environment
+function checkEnvironment(envName) {
+  // First check the custom environment variable from runtime
+  if (isBrowser() && window?.[PUBLIC_ENV_KEY]?.NEXT_PUBLIC_APP_ENV) {
+    return window[PUBLIC_ENV_KEY].NEXT_PUBLIC_APP_ENV === envName;
+  }
+  
+  // Then check process.env
+  if (process.env.NEXT_PUBLIC_APP_ENV) {
+    return process.env.NEXT_PUBLIC_APP_ENV === envName;
+  }
+  
+  // Fall back to NODE_ENV
+  return process.env.NODE_ENV === envName;
+}
+
+// Environment utility functions
+const isDevelopment = () => checkEnvironment("development");
+const isProduction = () => checkEnvironment("production");
+const isTest = () => checkEnvironment("test");
+const isStaging = () => checkEnvironment("staging");
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b63006f and e0127cb.

📒 Files selected for processing (5)
  • src/app/api/trpc/[trpc]/route.ts (2 hunks)
  • src/app/layout.tsx (2 hunks)
  • src/components/onboarding/signin/index.tsx (2 hunks)
  • src/env.js (3 hunks)
  • src/trpc/react.tsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/components/onboarding/signin/index.tsx (1)
src/env.js (2)
  • envUtils (81-86)
  • envUtils (81-86)
src/trpc/react.tsx (1)
src/env.js (2)
  • envUtils (81-86)
  • envUtils (81-86)
🔇 Additional comments (10)
src/env.js (2)

145-145: Good addition of NEXT_PUBLIC_APP_ENV to the client schema

Adding this environment variable to the schema with proper validation ensures consistency and provides more flexibility for environment control.


195-195: Ensures runtime access to NEXT_PUBLIC_APP_ENV

The addition to experimental__runtimeEnv correctly enables access to this variable at runtime through the helper function.

src/trpc/react.tsx (2)

10-10: Good import of envUtils

Importing the envUtils module for centralized environment detection.


26-26: Properly replaced direct NODE_ENV check with utility function

Using envUtils.isDevelopment() instead of directly checking process.env.NODE_ENV aligns with the centralized environment detection approach.

src/components/onboarding/signin/index.tsx (2)

30-30: Good import of envUtils

Importing the envUtils module for centralized environment detection.


51-52: Properly uses environment utilities for development defaults

Using envUtils.isDevelopment() for setting default form values ensures consistency with the rest of the application.

src/app/api/trpc/[trpc]/route.ts (2)

4-4: Updated import to include envUtils

Good addition of envUtils to the imports.


25-25: Replaced direct NODE_ENV check with utility function

Using envUtils.isDevelopment() instead of directly checking env.NODE_ENV aligns with the centralized environment detection approach.

src/app/layout.tsx (2)

5-5: Good addition of centralized environment utility.

This import aligns with the PR objective of centralizing environment detection logic across the codebase. Using a dedicated utility module is a good practice for consistent environment checks.


46-46: Properly implemented environment check.

The refactoring from direct NODE_ENV checks to envUtils.isDevelopment() ensures consistent environment detection throughout the application. This abstraction makes environment-specific behavior more maintainable and allows for more sophisticated environment detection logic in the future.

@erickmmolina erickmmolina reopened this May 22, 2025
@erickmmolina erickmmolina deleted the feature/env-mode-control branch May 24, 2025 03:46
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