-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix errors under NextJS #352
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes involve a refactoring of runtime environment detection and constant management across multiple files. The primary modifications include moving environment-specific constants and detection functions from Changes
Sequence DiagramsequenceDiagram
participant Runtime as runtime.ts
participant Constants as constants.ts
participant Clients as Clients
participant Tests as Tests
Runtime->>Runtime: Define runtime constants
Runtime->>Runtime: Create environment detection functions
Runtime-->>Constants: Export constants and functions
Constants-->>Clients: Import runtime utilities
Constants-->>Tests: Import runtime utilities
The sequence diagram illustrates how the new Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 (4)
src/lib/runtime.ts (3)
1-4
: Consider broader environment checks or fallback logic.Currently, if
process.versions.node
is absent, the code defaults to"unknown"
. In lesser-known or emerging runtimes that partially emulate Node, this may lead to confusing results. Consider providing a more descriptive fallback or performing deeper checks to ensure robust detection.
6-9
: Add fallback for unrecognized runtimes.Similar to
NODE_VERSION
, we return"unknown"
if the Bun version is missing. This is fine, but including more descriptive fallback logic or logging may help troubleshoot environment discrepancies when something mimics Bun but lacks a fully populatedprocess.versions
.
11-14
: Validate user agent behavior in non-browser contexts.The fallback to
"unknown"
is helpful, but consider whether a more explicit message or separate detection (e.g.,typeof window === "undefined"
) might be more informative for debugging scenarios in server-side or non-browser contexts.test/constants.test.ts (1)
10-10
: Add tests for additional environments if relevant.You’ve transitioned
isBrowser
andNODE_VERSION
toruntime.ts
. Consider adding unit tests or test configurations for Bun or other runtimes to confirm thatBUN_VERSION
is also handled properly in your test coverage.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
src/lib/constants.ts
(1 hunks)src/lib/helpers.ts
(0 hunks)src/lib/runtime.ts
(1 hunks)src/packages/AbstractLiveClient.ts
(1 hunks)src/packages/AbstractRestClient.ts
(1 hunks)test/constants.test.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- src/lib/helpers.ts
✅ Files skipped from review due to trivial changes (2)
- src/packages/AbstractLiveClient.ts
- src/packages/AbstractRestClient.ts
🔇 Additional comments (3)
src/lib/runtime.ts (1)
16-20
: Potential combined environment checks.
isBrowser()
,isNode()
, andisBun()
each check if the corresponding version or agent is not"unknown"
. These simple checks are adequate, but watch out for edge cases—e.g., a future environment that sets both Node and Bun versions. It may be beneficial to consolidate these checks in a single utility that ensures mutually exclusive detection or clarifies if running in a hybrid environment.src/lib/constants.ts (1)
1-2
: Imports reflect refactoring toward runtime detection.The updated imports from
./runtime
are well-organized. Ensure that any references to removed constants or functions in other modules are properly updated to prevent build or runtime failures.test/constants.test.ts (1)
1-1
: Confirm removal of isBrowser import from helpers.Removing
isBrowser
from the helpers import path is consistent with the new runtime-centric design. Ensure there are no leftover references to the old import in other tests or files.
This PR should fix some errors being shown when running the javascript sdk under NodeJS. I believe it was caused by a circular dependency that has been hence removed, as mentioned in issue #346
I have locally tested both running
npm test
and running my application with its built version as module.This is my first serious PR, feel free to let me know if I have something to improve on.
Summary by CodeRabbit
Refactor
Chores