Skip to content

Async component not rendering in SSR bundle, due to default export being missed #8351

Open
@AaronBeaudoin

Description

@AaronBeaudoin

Vue version

3.3.2

Link to minimal reproduction

https://github.com/AaronBeaudoin/vite-issue-ssr-vue-async

Steps to reproduce

See reproduction repository for steps.

The async component is not rendered after bundling because inside the defineAsyncComponent function the code to set the comp variable to the default export of the "module" is not being run.

When running, it is helpful to attach a debugger and break at the relevant code inside the defineAsyncComponent function so you can see the problem more clearly:

🔴 if (comp && (comp.__esModule || comp[Symbol.toStringTag] === "Module")) {
  comp = comp.default;
}

The challenge for me is that I'm not 100% sure if this issue is Vue's problem, or if there is something not being done over on esbuild's side to ensure this condition gets tripped. This problem is a blocker for my project though, so I need to start with an issue somewhere and hope someone helps quickly, otherwise my project is just at a standstill because my production site depends on my async components rendering in SSR for SEO purposes.

What is expected?

At a high level: The async component renders.
At a lower level: The "module" of the async component is detected as having a "default" export and the relevant code is run to properly set the comp variable inside of defineAsyncComponent.

What is actually happening?

At a high level: The async component does not render.
At a lower level: The "module" of the async component has a "default" export, but this is not detected and the relevant code is not run. As a result, the ssrRender function never runs and the component is not rendered.

System Info

System:
    OS: macOS 13.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 106.42 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 16.19.0 - ~/.volta/tools/image/node/16.19.0/bin/node
    npm: 8.19.3 - ~/.volta/tools/image/node/16.19.0/bin/npm
  Browsers:
    Chrome: 112.0.5615.49
    Safari: 16.4
  npmPackages:
    vue: ^3.3.2 => 3.3.2

Any additional comments?

I originally ran into this bug while using vite-plugin-ssr, but I was able to narrow the issue down to the linked minimal reproduction. As a result, it is clear that this issue affects at the very least all SSR projects utilizing async components and needing to bundle their server-side code, at least with esbuild (Ex: Cloudflare Workers).

Metadata

Metadata

Assignees

No one assigned

    Labels

    has workaroundA workaround has been found to avoid the problemneed guidanceThe approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.scope: ssr

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions