QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.84k stars 1.31k forks source link

[🐞] Client/server code splitting isn't powerful anymore since v1.7.0 #6666

Closed nelsonprsousa closed 4 months ago

nelsonprsousa commented 4 months ago

Which component is affected?

Qwik Runtime

Describe the bug

Server specific code should be excluded from the client. It was somewhat powerful up until v1.6.0 but stop being powerful at v.1.7.0.

Reproduction

https://github.com/nelsonprsousa/qwik-1.7.0-regression/commits/main/

Steps to reproduce

Run yarn following by yarn start.

You can change to v1.6.0 and it will work as expected.

Example code ```typescript import { isBrowser } from "@builder.io/qwik/build"; import { asyncContext as asyncContextClient } from "~/async-context/async-context.client"; import { asyncContext as asyncContextServer } from "~/async-context/async-context.server"; export const AsyncContext = isBrowser ? asyncContextClient : asyncContextServer; ```

Weirdly enough, if we use ESNext await import syntax, it still works. However, we will need to target ES2022 in the vite.config.ts file.

Working with ESNext syntax ```typescript import { isBrowser } from "@builder.io/qwik/build"; export const AsyncContext = isBrowser ? (await import("./async-context.client")).asyncContext : (await import("./async-context.server")).asyncContext; ```
Main error on client ``` Module "node:async_hooks" has been externalized for browser compatibility. Cannot access "node:async_hooks.AsyncLocalStorage" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. ```
Stack Trace ```bash Error: Module "node:async_hooks" has been externalized for browser compatibility. Cannot access "node:async_hooks.AsyncLocalStorage" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. at Object.get (http://localhost:5173/@id/__vite-browser-external:node:async_hooks:3:11) at http://localhost:5173/src/async-context/async-context.server.ts:1:159 ```

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
    Memory: 37.61 GB / 63.72 GB
  Binaries:
    Node: 21.7.3 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.5.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.15.4 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (126.0.2592.87)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @builder.io/qwik: 1.7.0 => 1.7.0
    @builder.io/qwik-city: 1.7.0 => 1.7.0
    typescript: 5.4.5 => 5.4.5
    undici: * => 6.19.2
    vite: ^5.2.10 => 5.3.3

Additional Information

No response

shairez commented 4 months ago

Thanks for the report @nelsonprsousa

We'll fix it