Skip to content

fix(sdk): bind fetch to globalThis for Cloudflare Workers#41

Merged
khaliqgant merged 1 commit into
mainfrom
fix/sdk-fetch-binding
Apr 16, 2026
Merged

fix(sdk): bind fetch to globalThis for Cloudflare Workers#41
khaliqgant merged 1 commit into
mainfrom
fix/sdk-fetch-binding

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

@khaliqgant khaliqgant commented Apr 16, 2026

Summary

  • Fixes "Illegal invocation" error when RelayFileClient is used in Cloudflare Workers
  • The default fetch was stored as this.fetchImpl without preserving its this binding, causing Cloudflare Workers to throw when calling it as a method
  • Fix: fetch.bind(globalThis) at construction time

Context

Sage's SageRelayFileReader.listGitHubRepos() was failing with:

Illegal invocation: function called with incorrect `this` reference

This prevented Sage from reading the relayfile VFS entirely.

Test plan

  • Verify Sage no longer throws "Illegal invocation" when reading from relayfile
  • Verify SDK still works in Node.js environments (fetch.bind is a no-op there)

🤖 Generated with Claude Code


Open with Devin

Cloudflare Workers throws "Illegal invocation" when `fetch` is stored
as a property and called with the wrong `this` binding. Binding to
globalThis at construction time preserves the correct context.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@khaliqgant khaliqgant merged commit f050c6f into main Apr 16, 2026
6 checks passed
@khaliqgant khaliqgant deleted the fix/sdk-fetch-binding branch April 16, 2026 15:22
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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.

1 participant