Skip to content
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

browser value from $app/environment shows the wrong value in the server environment #8082

Closed
0x221A opened this issue Dec 12, 2022 · 3 comments · Fixed by #8083 or #8092
Closed

browser value from $app/environment shows the wrong value in the server environment #8082

0x221A opened this issue Dec 12, 2022 · 3 comments · Fixed by #8083 or #8092
Labels
bug Something isn't working

Comments

@0x221A
Copy link
Contributor

0x221A commented Dec 12, 2022

Describe the bug

The browser value from $app/environment should be false in a server environment but the value is true. This issue appears in @sveltejs/kit 1.0.0-next.580 and later versions. It prevents some features (e.g. $app/navigation and $page) from working and the error occurs in some serverless adapters.

Reproduction

Rollback to @sveltejs/kit 1.0.0-next.579

Logs

TypeError: Cannot read properties of undefined (reading 'disable_scroll_handling')
    at .svelte-kit/output/server/entries/pages/_layout.svelte.js (/Users/.../.svelte-kit/output/server/entries/pages/_layout.svelte.js:13:18)
    at __init (/private/var/folders/9t/gvy_vyd1721gjwcmrmlp03t80000gn/T/tmp-96434-lap9SAEoeRwX/1sxur97ubl8.js:29:56)
    at /Users/.../.svelte-kit/output/server/nodes/0.js:4:45
    at Object.component (/Users/.../.svelte-kit/output/server/nodes/0.js:4:39)
    at async Promise.all (index 0)
    at render_response (/Users/.../.svelte-kit/output/server/index.js:1132:19)
    at render_page (/Users/.../.svelte-kit/output/server/index.js:1633:12)
    at resolve (/Users/.../.svelte-kit/output/server/index.js:2361:22)
    at respond (/Users/.../.svelte-kit/output/server/index.js:2255:22)
    at Object.fetch (/Users/.../.svelte-kit/cloudflare-tmp/_worker.js:72:15)
GET / 500 Internal Server Error (117.19ms)
GET /_app/immutable/start-64dae5f6.js 200 OK (15.17ms)
GET /_app/immutable/components/pages/_layout.svelte-468b3563.js 200 OK (7.76ms)
GET /_app/immutable/chunks/0-3dc960e5.js 200 OK (9.19ms)
GET /favicon.png 304 Not Modified (3.74ms)

System Info

System:
    OS: macOS 13.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 87.06 MB / 16.00 GB
    Shell: 3.5.1 - /usr/local/bin/fish
  Binaries:
    Node: 16.18.1 - ~/Library/Caches/fnm_multishells/90960_1670456193433/bin/node
    Yarn: 3.3.0 - /usr/local/bin/yarn
    npm: 8.19.2 - ~/Library/Caches/fnm_multishells/90960_1670456193433/bin/npm
  Browsers:
    Chrome: 108.0.5359.98
    Safari: 16.2
  npmPackages:
    @sveltejs/adapter-cloudflare: =1.0.0-next.41 => 1.0.0-next.41 
    @sveltejs/kit: =1.0.0-next.582 => 1.0.0-next.582 
    svelte: ^3.54.0 => 3.54.0 
    vite: ^4.0.0 => 4.0.0

Severity

blocking an upgrade

Additional Information

I thought that this problem is related to #8047 and #7950.

@gtm-nayan
Copy link
Contributor

@0x221A are you deploying to Cloudflare?

If so I believe the problem originates here, those adapters tell esbuild to build for a browser environment because their runtime matches a browser more than node, but that also causes it to load true for BROWSER from esm-env.

@0x221A
Copy link
Contributor Author

0x221A commented Dec 12, 2022

@gtm-nayan Yes, that is true that those adapters tell esbuild to build for a browser but should not tell that the current code is running in the server or the browser. The problem is this causes an error in the worker script when trying to render the component to an HTML string i.e. when we want to use the goto function from $app/navigation. The $app/navigation has a guard function to prevent the server to use it before it initializes. So if browser is true then it will use the undefined value then throw an error. So even if the target platform is the browser it doesn't mean that the whole code is running in the browser environment in this case because Cloudflare Worker supported only browser API which doesn't mean that the server-side code is running in a real browser.

https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/app/navigation.js#L13-L15

@MelodicCrypter
Copy link

I'm also experiencing the "disable_scroll_handling" issue

Screenshot 2023-04-14 at 1 58 30 PM

Using: "@sveltejs/kit": "^1.15.5"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants