refactor: Add timers polyfill to DHT package for standalone browser usage#3379
Merged
mondoreale merged 4 commits intomainfrom Feb 3, 2026
Merged
refactor: Add timers polyfill to DHT package for standalone browser usage#3379mondoreale merged 4 commits intomainfrom
timers polyfill to DHT package for standalone browser usage#3379mondoreale merged 4 commits intomainfrom
Conversation
It's too late in SDK. Someone might wanna use DHT without SDK and they have to polyfill themselves.
timers polyfill from SDK to DHT packagetimers polyfill to DHT package for standalone browser usage
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds browser compatibility to the @streamr/dht package by including a polyfill for setImmediate, which is not natively available in browsers but is used extensively throughout the DHT codebase. The change mirrors the existing approach in the SDK package and enables standalone DHT usage in browser environments without requiring consumers to manually configure polyfills.
Changes:
- Added
timers-browserifydependency to@streamr/dhtpackage - Configured
import 'timers'polyfill at the entry point of DHT exports - Added rollup configuration to alias
timerstotimers-browserifyfor browser builds
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/dht/src/exports.ts | Added timers import with explanatory comment at the top of exports to ensure setImmediate is available before any DHT code executes |
| packages/dht/package.json | Added timers-browserify dependency (^2.0.12) to support browser environments |
| packages/dht/rollup.config.mts | Added timers→timers-browserify alias for browser builds and applied code formatting improvements |
| packages/sdk/src/StreamrClient.ts | Minor formatting change (added blank line) for consistency |
| package-lock.json | Updated lock file to reflect new timers-browserify dependency in DHT package |
| CHANGELOG.md | Documented the addition of timers-browserify polyfill for standalone browser usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the
timers-browserifypolyfill to the DHT package, enabling standalone DHT usage in browsers without requiring consumers to manually polyfillsetImmediate. The SDK retains its existing polyfill for redundancy.Changes
timers-browserifydependency to@streamr/dhtpackageimport 'timers'polyfill in DHT'sexports.tsfor browser compatibilitytimers→timers-browserifyalias in DHT's rollup browser config