Skip to content

Conversation

@dplewis
Copy link
Member

@dplewis dplewis commented Jan 8, 2026

Pull Request

Issue

Since we don't have tree shaking the ws module gets included in the react-native build when it's not used

Closes: #2633

Before:
450291218-be773c1d-e324-4149-a08e-59fbe12c2e01

After:
Screenshot 2026-01-08 at 7 16 37 AM

Summary by CodeRabbit

  • Refactor
    • Updated internal module loading mechanism for improved build compatibility. No changes to functionality or user-facing features.

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

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: ws package causes React-Native build failure fix: Ws package causes React-Native build failure Jan 8, 2026
@parse-github-assistant
Copy link

parse-github-assistant bot commented Jan 8, 2026

🚀 Thanks for opening this pull request!

@coderabbitai
Copy link

coderabbitai bot commented Jan 8, 2026

📝 Walkthrough

Walkthrough

The change converts static imports of ws and Socket.weapp modules to runtime require() calls in the Node.js and WeChat Web App build branches of WebSocketController. This allows conditional module loading based on the execution environment without bundler interference.

Changes

Cohort / File(s) Summary
Import conversion
src/WebSocketController.ts
Replaced static imports with runtime require('ws') and require('./Socket.weapp') in node and weapp branches; browser and react-native branches unchanged; existing try/catch block retained.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: ws package causes React-Native build failure' directly addresses the main change - replacing static imports with runtime requires to prevent the ws module from being bundled in React-Native builds.
Description check ✅ Passed The description covers the Issue section with a link to #2633, explains the problem clearly, and includes before/after screenshots demonstrating the fix. However, the Approach and Tasks sections are not completed.
Linked Issues check ✅ Passed The code changes address the core requirement from issue #2633 by using runtime requires instead of static imports to prevent the ws module from being bundled in React-Native builds where Node core modules are unavailable.
Out of Scope Changes check ✅ Passed The changes are limited to WebSocketController.ts and directly address the bundling issue by modifying how ws and Socket.weapp modules are imported across different build targets.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf2ef13 and 70c9932.

📒 Files selected for processing (1)
  • src/WebSocketController.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/WebSocketController.ts (2)
src/CoreManager.ts (1)
  • WebSocketController (299-306)
src/__tests__/LiveQueryClient-test.js (2)
  • WebSocketController (43-43)
  • require (44-44)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build (Node 20, 20.19.0)
  • GitHub Check: build (Node 22, 22.12.0)
  • GitHub Check: build (Node 24, 24.1.0)
🔇 Additional comments (1)
src/WebSocketController.ts (1)

9-11: LGTM! Runtime require() prevents static bundling.

The conversion to runtime require() calls correctly addresses the React Native build failure. By deferring module resolution to runtime within conditional branches, bundlers like Metro won't statically analyze and include ws (and its Node.js dependencies like stream) in React Native builds.

Verify that:

  • React Native builds now succeed without the ws bundling error
  • Node.js builds still correctly load the ws module
  • WeChat Web App builds still correctly load Socket.weapp

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.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Jan 8, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@dplewis dplewis changed the title fix: Ws package causes React-Native build failure fix: ws package causes React-Native build failure Jan 8, 2026
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8cb510c) to head (297a0a4).

Additional details and impacted files
@@            Coverage Diff            @@
##             alpha     #2857   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         6222      6222           
  Branches      1473      1489   +16     
=========================================
  Hits          6222      6222           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dplewis dplewis requested a review from a team January 8, 2026 15:09
@mtrezza mtrezza requested review from Copilot and removed request for a team January 10, 2026 12:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a React-Native build failure caused by the ws package being included in the bundle despite not being used in that build target. The fix converts static imports to dynamic requires that are evaluated at runtime based on the PARSE_BUILD environment variable.

Changes:

  • Converted static ES6 imports (import ws from 'ws' and import SocketWeapp from './Socket.weapp') to dynamic CommonJS requires within conditional blocks
  • This prevents bundlers from including unused WebSocket implementations in platform-specific builds

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

The package at "node_modules/parse/node_modules/ws/lib/stream.js" attempted to import the Node standard library module "stream"

3 participants