Skip to content

fix: prevent process.env access from crashing browser builds - #812

Open
Kanhaiyaarora wants to merge 1 commit into
react-grid-layout:masterfrom
Kanhaiyaarora:fix-process-env-browser-error
Open

fix: prevent process.env access from crashing browser builds#812
Kanhaiyaarora wants to merge 1 commit into
react-grid-layout:masterfrom
Kanhaiyaarora:fix-process-env-browser-error

Conversation

@Kanhaiyaarora

@Kanhaiyaarora Kanhaiyaarora commented Jul 27, 2026

Copy link
Copy Markdown

Summary

This PR prevents runtime errors in browser environments by safely checking for the existence of process before accessing process.env.DRAGGABLE_DEBUG.

Problem

The current implementation directly accesses process.env.DRAGGABLE_DEBUG:

if (process.env.DRAGGABLE_DEBUG) console.log(...args);

In browser environments where process is not defined (e.g., Vite without a process polyfill), this can lead to runtime errors and affect components that depend on react-draggable.

Solution

Added a guard to ensure process exists before accessing process.env:

if (typeof process !== "undefined" && process.env?.DRAGGABLE_DEBUG) {
  console.log(...args);
}

This preserves the existing debug logging behavior while preventing errors in environments where process is unavailable.

Testing

  • Verified the issue in a React + Vite application.
  • Confirmed that the runtime error no longer occurs.
  • Confirmed that drag functionality works correctly after the change.
  • Verified that debug logging behavior remains unchanged when DRAGGABLE_DEBUG is enabled.
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility in environments without a process object.
    • Debug logging now appears only when explicitly enabled through the debug setting.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ee2bd4a-6149-4115-b063-2c8556b24fca

📥 Commits

Reviewing files that changed from the base of the PR and between a0b6e21 and e130d5b.

📒 Files selected for processing (1)
  • lib/utils/log.ts

📝 Walkthrough

Walkthrough

The logging utility now guards access to process and optionally reads DRAGGABLE_DEBUG before calling console.log.

Changes

Debug logging guard

Layer / File(s) Summary
Guard process and environment access
lib/utils/log.ts
The log function checks whether process exists and uses optional environment access before enabling debug output.

Estimated code review effort: 2 (Simple) | ~5 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: guarding process.env access to prevent browser build crashes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

lib/utils/log.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


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.

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