Skip to content

fix(supabase): safe environment detection node v browser#2053

Merged
mandarini merged 1 commit into
masterfrom
fix/environment-detection
Jan 26, 2026
Merged

fix(supabase): safe environment detection node v browser#2053
mandarini merged 1 commit into
masterfrom
fix/environment-detection

Conversation

@mandarini

@mandarini mandarini commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

Direct access and require of process caused issue in Next.js builds. Needed a safer way to do environment detection. Used pattern already present in websocket-factory.

Fix for issue caused by #2046

Summary by CodeRabbit

  • Bug Fixes

    • Improved platform and runtime detection to work reliably across different environments (browser, Node.js server).
  • Tests

    • Enhanced test configuration and setup for better compatibility with various JavaScript environments.
    • Refined environment-specific test assertions to accurately validate behavior in server and browser contexts.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The changes add Jest setup configuration to globally expose the require function and modify platform/runtime detection in the client constants to use dynamic property access and environment-aware checks, avoiding bundler static analysis issues while ensuring proper server-side detection.

Changes

Cohort / File(s) Summary
Jest Configuration
packages/core/supabase-js/jest.config.ts, packages/core/supabase-js/jest.setup.ts
Added setupFilesAfterEnv entry to Jest config to load setup script. New jest.setup.ts polyfill exposes globalThis.require when ts-jest doesn't provide it, ensuring require is accessible during tests.
Platform & Runtime Detection
packages/core/supabase-js/src/lib/constants.ts
Replaced direct process global access with dynamic property access via (globalThis as any)['process'] to prevent bundler static analysis. Added platform checks for android and iOS, conditional require('os') for server-side Node contexts, and null-safe guards around process usage.
Test Updates
packages/core/supabase-js/test/unit/constants.test.ts
Renamed test and refactored to add explicit server-side environment guards (typeof window === 'undefined'). Ensures platformVersion and runtimeVersion assertions run only in non-browser environments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hops through the code with glee,
Dynamic properties dance so free,
Jest setup blooms, platform checks grow,
Bundlers deceived—now the truth they'll know!

🚥 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: refactoring environment detection to use bracket notation for accessing require and process properties to fix build issues.

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

✨ Finishing touches
  • 📝 Generate docstrings

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.

@github-actions github-actions Bot added the supabase-js Related to the supabase-js library. label Jan 23, 2026
@mandarini mandarini self-assigned this Jan 23, 2026
@mandarini mandarini marked this pull request as ready for review January 26, 2026 14:09
@mandarini mandarini requested a review from a team as a code owner January 26, 2026 14:09
@mandarini mandarini changed the title fix(supabase): environment detection require in brackets fix(supabase): safe environment detection node v browser Jan 26, 2026
@mandarini mandarini merged commit bd3808c into master Jan 26, 2026
23 of 24 checks passed
@mandarini mandarini deleted the fix/environment-detection branch January 26, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

supabase-js Related to the supabase-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants