Skip to content

[🐞] Qwik is bundling server side dependencies with client code #7172

@DustinJSilk

Description

@DustinJSilk

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/A

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TYPE: bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions