You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Bug
In FetchAdapter, the generated code does this:
ts
this.fetchFn = fetchFn ?? createFetch(); // step 1: store fetch as property
// ...
const response = await this.fetchFn(url, opts); // step 2: call it
When createFetch() runs in the browser, it returns globalThis.fetch — which is window.fetch. The problem is step 2: calling this.fetchFn(...) invokes fetch with this === the FetchAdapter instance, but native window.fetch requires this === window. That's what "Illegal invocation" means — the browser rejects the call because this is wrong.In plain terms: storing a native function as an object property and then calling it detaches it from its original owner. Same reason "hello".trim works but const fn = "hello".trim; fn() throws.
sdk/constructive-sdk/src/public/orm/client.ts:61 and the other 12 checked-in generated SDK clients still contain this.fetchFn = fetchFn ?? createFetch();.
.ie need to regenerate all sdks in this monorepo
The added regression tests are weak. The substring assertion at PR test lines 80-87 only proves .bind(globalThis) appears somewhere in generated text, not that FetchAdapter binds the selected fetch function correctly. It would pass with .bind(globalThis) in a comment or
with the precedence bug fetchFn ?? createFetch().bind(globalThis). The second test at lines 89-105 does not instantiate FetchAdapter; it tests JavaScript bind() behavior in isolation.
The second test also does not match native browser timing exactly. In Chrome, detached window.fetch returns a Promise and then rejects with TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation; it does not synchronously throw. The production await
this.fetchFn(...) still observes it as a failure, but the test is a simplified demo, not a browser-faithful regression.
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
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.
The Bug
In FetchAdapter, the generated code does this:
ts
this.fetchFn = fetchFn ?? createFetch(); // step 1: store fetch as property
// ...
const response = await this.fetchFn(url, opts); // step 2: call it
When createFetch() runs in the browser, it returns globalThis.fetch — which is window.fetch. The problem is step 2: calling this.fetchFn(...) invokes fetch with this === the FetchAdapter instance, but native window.fetch requires this === window. That's what "Illegal invocation" means — the browser rejects the call because this is wrong.In plain terms: storing a native function as an object property and then calling it detaches it from its original owner. Same reason "hello".trim works but const fn = "hello".trim; fn() throws.