-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hotfix: with nodeAdapter we should get fetch from globalThis #1786
Conversation
|
@@ -215,7 +215,7 @@ class Watcher extends EventEmitter { | |||
hooks: { | |||
getSession: hooks.getSession || (() => ({})), | |||
handle: hooks.handle || (({ request, resolve }) => resolve(request)), | |||
serverFetch: hooks.serverFetch || fetch | |||
serverFetch: hooks.serverFetch || globalThis.fetch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the fetch call inside serverFetch
? Does that also need to be scoped with globalThis.
, or does this only affect the default case of not having serverFetch
defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it's fallback, serverFetch
is optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or does this only affect the default case of not having serverFetch defined?
yes.
This comment has been minimized.
This comment has been minimized.
I see globalThis.fetch = fetch2; on line ~3k of the output, but there's an init function on line ~1.7k that ends up calling fetch, so I guess they've gotten put out of order somehow It seems to be this init: kit/packages/kit/src/core/build/index.js Line 290 in 6ace879
I don't quite understand how all these build pieces fit together, but in my limited understanding this PR seems to be papering over the issue2, which is that |
I expect we may be hitting an incorrect assumption in esbuild: evanw/esbuild#399 (comment) |
Oof, that's a surprising issue. This does indeed seem to be an ordering issue — anything added to // foo.js
globalThis.foo = 42; // index.js
import './foo.js';
console.log(foo); // 42 Is this something that broke recently? |
@Rich-Harris, yes, it started after d729b08#diff-ed48923f0655f935bee505cdcbf40212129ff49a89c2c9d752bd63aa1e6282c4R191 |
@benmccann, yes, I totally agree, it's just hiding some order issue, but at the same time, it can be a temporal solution while we are trying to find and fix it. |
I just noticed, but turns out this PR actually changes the dev environment, not the build one, so it's actually modifying the wrong files to fix the issue. Anyway, opened #1804 to try and deal with the root ordering issue rather than patch the symptoms. |
strange, at least I can't reproduce this issue anymore from #1784 after this PR. |
Base on #1784 issue. Basically, under real nodejs we have no direct access to
fetch
even if it's set to globalThis.