question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: transport that does not depend on global fetch

See original GitHub issue

Describe the feature you’d like to request

I’d like to see a transport layer that is pluggable and allows for other implementations to exist and does not assume the existence of fetch in the global (or window) scope.

Describe the solution you’d like to see

A well-defined interface for the transport layer that can be easily swapped out for other implementations.

Desribe alternate solutions

Global patching, described here: https://github.com/trpc/trpc/discussions/1982

Additional information

Related: https://github.com/trpc/trpc/discussions/1982

Node 18 announcement: https://nodejs.org/de/blog/announcements/v18-release-announce/#new-globally-available-browser-compatible-apis

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I’d be down to file a PR implementing this feature!

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
KATTcommented, Sep 13, 2022

We should probably do this tbh:

export interface TRPCClientRuntime {
-  fetch: TRPCFetch;
-  AbortController?: typeof AbortController;
-  headers: () => HTTPHeaders | Promise<HTTPHeaders>;
  transformer: DataTransformer;
}

And


export interface HTTPLinkOptions {
  url: string;
+  fetch?: TRPCFetch;
+  AbortController?: typeof AbortController;
+  headers?: () => HTTPHeaders | Promise<HTTPHeaders>;
}
1reaction
jlalmescommented, Sep 13, 2022

Hi @moltar - this is already possible, I think you are describing the purpose of adapters (router-side) and links (client-side). Please see trpc-chrome as an example for web extensions where the message passing transport layer is: chrome.runtime.connect(...).

Read more comments on GitHub >

github_iconTop Results From Across the Web

fetch() performance parity · Issue #1203 · nodejs/undici - GitHub
I wrote up a tiny DoH load-tester with python and golang (don't ask) which I intend to publish as a github action by...
Read more >
Simple fetch mock using Typescript and Jest - Stack Overflow
You can tell TypeScript that you're defining global.fetch as a Jest mock. global.fetch = jest.fn(() => Promise.resolve({ json: ...
Read more >
How To Mock Fetch in Jest | Leigh Halliday
In our case we can do this, and that is because fetch is available globally. So instead we will override the global.
Read more >
New Node.js features, Node latest version report | TSH.io
Node 18 features an experimental global fetch API, which enables the same methods without having to rely on external packages.
Read more >
Voice Extensible Markup Language (VoiceXML) Version 2.0
In this document, the key words "must", "must not", "required", "shall", "shall not", "should", "should not", "recommended", "may", and " ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found