Skip to content

refactor: Add timers polyfill to DHT package for standalone browser usage#3379

Merged
mondoreale merged 4 commits intomainfrom
polyfill-timers-in-dht
Feb 3, 2026
Merged

refactor: Add timers polyfill to DHT package for standalone browser usage#3379
mondoreale merged 4 commits intomainfrom
polyfill-timers-in-dht

Conversation

@mondoreale
Copy link
Contributor

Summary

Adds the timers-browserify polyfill to the DHT package, enabling standalone DHT usage in browsers without requiring consumers to manually polyfill setImmediate. The SDK retains its existing polyfill for redundancy.

Changes

  • Add timers-browserify dependency to @streamr/dht package
  • Add import 'timers' polyfill in DHT's exports.ts for browser compatibility
  • Configure timerstimers-browserify alias in DHT's rollup browser config

It's too late in SDK. Someone might wanna use DHT without SDK and they have to polyfill themselves.
@github-actions github-actions bot added dht Related to DHT package sdk labels Feb 3, 2026
@github-actions github-actions bot added the docs label Feb 3, 2026
@mondoreale mondoreale changed the title refactor: Move timers polyfill from SDK to DHT package refactor: Add timers polyfill to DHT package for standalone browser usage Feb 3, 2026
@mondoreale mondoreale changed the title refactor: Add timers polyfill to DHT package for standalone browser usage refactor: Add timers polyfill to DHT package for standalone browser usage Feb 3, 2026
@mondoreale mondoreale requested a review from Copilot February 3, 2026 15:12
Copy link
Contributor

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 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-browserify dependency to @streamr/dht package
  • Configured import 'timers' polyfill at the entry point of DHT exports
  • Added rollup configuration to alias timers to timers-browserify for 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.

@mondoreale mondoreale merged commit 5d35c22 into main Feb 3, 2026
50 of 51 checks passed
@mondoreale mondoreale deleted the polyfill-timers-in-dht branch February 3, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dht Related to DHT package docs sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant