Commit aff6c24
authored
fix(client): resolve default fetch lazily so interception tools work regardless of link construction order (#1901)
FetchLinkTransport captured `globalThis.fetch` at construction time
(`options.fetch ?? globalThis.fetch.bind(globalThis)`), so any link
created before a tool patches the global fetch — msw's `setupServer`,
undici's `MockAgent`, and similar interceptors — permanently bypassed
the patched implementation, surfacing as confusing ECONNREFUSED failures
in tests. The default is now a late-bound wrapper, `(url, init) =>
globalThis.fetch(url, init)`, resolved on every request.
## Fixes
- Links constructed before fetch interception is installed are now
intercepted correctly; construction order no longer matters.
- The default now forwards only `(url, init)` to the global fetch,
matching the native signature; an explicit `fetch` option still receives
`(url, init, options, path)` as before.
## Testing
- New regression test constructs the link first, patches
`globalThis.fetch` afterward, and verifies the patched fetch is used.
- Existing default-fetch test updated to the native two-argument call
shape; all fetch adapter tests pass, `pnpm type:check` clean across
packages.
This was the only eager-binding site — the websocket and message-port
transports take explicit instances.1 parent 2a80b57 commit aff6c24
2 files changed
Lines changed: 35 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
153 | 182 | | |
154 | | - | |
| 183 | + | |
| 184 | + | |
155 | 185 | | |
156 | | - | |
157 | 186 | | |
158 | 187 | | |
159 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
| |||
0 commit comments