-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed as not planned
Labels
TYPE: bugSomething isn't workingSomething isn't working
Description
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:
import { component$, useVisibleTask$ } from "@builder.io/qwik";
import { server$ } from "@builder.io/qwik-city";
import { SomeEnum } from "~/generated/some/v1/enum_pb";
import { createConnectTransport } from "@connectrpc/connect-node";
import { createPromiseClient } from "@connectrpc/connect";
import { SomeService } from "~/generated/some/v1/service_connect";
// Required to cache the services
class Grpc {
private static transport = createConnectTransport({
httpVersion: "2",
baseUrl: "https://www.test.com",
});
static service = createPromiseClient(SomeService, this.transport);
}
export const fooServerFunc = server$(async function () {
// Calling some server side code
await Grpc.service.someFetch({});
});
export default component$(() => {
// Without calling the server$, the error doesn't occur:
useVisibleTask$(() => {
fooServerFunc();
});
// Without this, the error doesn't occur:
return <div>{Math.random() == SomeEnum.A ? 1 : 2}</div>;
});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
N/AAdditional Information
No response
Metadata
Metadata
Assignees
Labels
TYPE: bugSomething isn't workingSomething isn't working
Type
Projects
Status
Done