-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[🐞] Qwik is bundling server side dependencies with client code #7172
Comments
Instead of using a static class, calling a function which caches the services on the global object solves the issue when using a if (isBrowser) throw new Error('...') |
Ok so in 1.8.0 I upgraded Rust and had do rewrite some logic, including the side effects visitor. Looks like it wasn't done quite correctly, or maybe it's more correct now. Looking into it. |
Ye it might be more correct now! Everything seems to be working quite well now with the above fixes |
So I checked and the tree shaking works but what happens is that the class definition is kept in the main .js file and exported for the server function. The server function actually gets built on the client (but never used) I think if we can empty out server functions in the client build it will be ok. To do that, I think the qrl extraction can get a flag not to emit any code. It still needs to walk the code to find other qrls that are used, like when returning a function from a server$ call. |
I was wrong, it does not output the server functions. What happens is that after doing the segmentation the So I'm going to close this one, because the tree shaking is working correctly, it's just that SWC won't clear an unused class. I opened swc-project/swc#9808, maybe that will get fixed. |
Thanks for the update! That makes sense and it’s simple enough to work around until swc can get it fixed. |
@DustinJSilk see the linked issue, the reason was actually that you store the transport stuff as statics, thus creating side effects. If you don't do that, it removes the code. |
@DustinJSilk so here's how to make it work correctly, you only initialize the statics on the server: import { component$, useVisibleTask$, isServer } from "@builder.io/qwik";
// ... rest
// Note the isServer guards
class Grpc {
private static transport = isServer ? createConnectTransport({
httpVersion: "2",
baseUrl: "https://www.test.com",
}) : null;
static service = isServer ? createPromiseClient(SomeService, this.transport) : null;
}
// ... rest |
Which component is affected?
Qwik Runtime
Describe the bug
Qwik is not effectively treeshaking server side code when bundling for the browser with production or preview builds.
This has been happening since before v1.5.7, however, it was not causing an error as the bundled server code was not loaded in the browser. This can be seen by the fact that there is a 500kb client bundle on version 1.5.7 but no browser error.
Since v.1.8.0, an error occurs because the code is now bundled differently and runs in the browser which crashes the website.
This is the code which results in an error:
Reproduction
https://github.com/DustinJSilk/qwik-preview-url/blob/main/src/routes/index.tsx
Steps to reproduce
Clone the repo
Run pnpm preview
View error in browser
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: