Skip to content

Conversation

@thruflo
Copy link
Contributor

@thruflo thruflo commented Dec 31, 2025

Summary

  • Adds a console.warn when the TypeScript client is used to connect to a shape on an HTTP URL (not HTTPS) in browser environments
  • HTTP forces HTTP/1.1 which limits browsers to 6 concurrent connections, causing slow shapes and potential app freezes with multiple shapes
  • Links to https://bit.ly/electric-http2 for more information

Changes

  • packages/typescript-client/src/client.ts: Added defensive check in validateOptions() that warns about HTTP URLs in browser environments
  • packages/typescript-client/test/stream.test.ts: Added unit tests verifying:
    • HTTP URLs trigger the warning in browsers
    • HTTPS URLs do not trigger the warning
    • Non-browser environments (Node.js) do not trigger the warning

HTTP (not HTTPS) forces HTTP/1.1 in browsers, which limits concurrent
connections to 6 per domain. This can cause slow shapes and app freezes
when using multiple shapes. Add a console.warn to alert developers about
this limitation and link to documentation for setting up HTTPS/HTTP2.
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 31, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@electric-sql/react@3661
npm i https://pkg.pr.new/@electric-sql/client@3661
npm i https://pkg.pr.new/@electric-sql/y-electric@3661

commit: c1c97cc

@thruflo thruflo changed the title Explore ElectricSQL TypeScript client documentation Warn in the TypeScript Client when using HTTP for shape URLs. Dec 31, 2025
@codecov
Copy link

codecov bot commented Dec 31, 2025

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.96%. Comparing base (b8fcb6f) to head (c1c97cc).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/typescript-client/src/client.ts 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3661      +/-   ##
==========================================
+ Coverage   87.91%   87.96%   +0.05%     
==========================================
  Files          22       22              
  Lines        1820     1845      +25     
  Branches      459      469      +10     
==========================================
+ Hits         1600     1623      +23     
- Misses        218      220       +2     
  Partials        2        2              
Flag Coverage Δ
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/start 89.58% <ø> (ø)
packages/typescript-client 93.63% <92.00%> (-0.04%) ⬇️
packages/y-electric 56.05% <ø> (ø)
typescript 87.96% <92.00%> (+0.05%) ⬆️
unit-tests 87.96% <92.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blacksmith-sh

This comment has been minimized.

Tests verify that:
- HTTP URLs trigger a console.warn in browser environments
- HTTPS URLs do not trigger the warning
- Non-browser environments (no window) do not trigger the warning
Add vitest setup file that filters the Electric HTTP warning to avoid
spamming test output. The warning is still tested explicitly in
stream.test.ts.
Users can now pass `warnOnHttp: false` to suppress the browser console
warning about HTTP URLs limiting concurrent connections.

Test setup filters all [Electric] prefixed warnings to keep logs clean.
@KyleAMathews
Copy link
Contributor

- Guard process.env.NODE_ENV access with typeof check to prevent
  ReferenceError in browser builds where process is not defined
- Add relative URL handling using window.location.href as base,
  so relative URLs like /v1/shape now correctly trigger warnings
  when the page is served over HTTP
- Add module-level didWarnOnHttp flag to warn only once per
  process/module, preventing log spam with multiple ShapeStreams
- Update warning wording to "typically limits browsers to ~6
  concurrent connections per origin under HTTP/1.1"
- Replace bit.ly short link with canonical docs URL
  https://electric-sql.com/r/electric-http2
- Add redirect in website _redirects for /r/electric-http2
- Add comprehensive tests for relative URL behavior and warn-once
- Properly clean up test globals (delete window if not present)
@netlify
Copy link

netlify bot commented Jan 6, 2026

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit c1c97cc
🔍 Latest deploy log https://app.netlify.com/projects/electric-next/deploys/695c8fcdbc246300084d83c4
😎 Deploy Preview https://deploy-preview-3661--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@thruflo
Copy link
Contributor Author

thruflo commented Jan 6, 2026

@KyleAMathews addressed (and read code and tested in browser).

@thruflo thruflo requested a review from KyleAMathews January 6, 2026 05:13
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.

4 participants