Skip to content

fix: preserve transitive server$ modules in SSR builds#8818

Merged
wmertens merged 3 commits into
build/v2from
v2-fix-serverfn-discovery
Jul 9, 2026
Merged

fix: preserve transitive server$ modules in SSR builds#8818
wmertens merged 3 commits into
build/v2from
v2-fix-serverfn-discovery

Conversation

@Varixo

@Varixo Varixo commented Jul 9, 2026

Copy link
Copy Markdown
Member

Fixes SSR server function registration when server$ is only reachable through stripped client-side code or transitive imports. The router now preserves discovered server function modules through tree-shaking, including packages marked with sideEffects: false.

Examples:

  1. Transitive server$ import
// route.tsx
import { ProductPage } from './product-page';
// product-page.tsx
import { emitViewContent } from './emit-view-content';

export const ProductPage = component$(() => {
  // ...
});
// emit-view-content.ts
const emitViewContentServer = server$(async function () {
  return 'ok';
});

export async function emitViewContent() {
  return emitViewContentServer();
}

Fixed path:

route -> product-page -> emit-view-content -> server$
2. server$ only used inside stripped client code

import { emitViewContent } from './emit-view-content';

useVisibleTask$(async () => {
  await emitViewContent();
});

Before, SSR stripping removed the visible task usage, so the import could disappear from the SSR graph.

  1. Dynamic import inside stripped client code
useVisibleTask$(async () => {
  const { emitViewContent } = await import('./emit-view-content');
  await emitViewContent();
});

Before, the literal dynamic import was lost when useVisibleTask$ was stripped from SSR.

  1. Modules inside packages with sideEffects: false
{
  "sideEffects": false
}
// emit-view-content.ts
const emitViewContentServer = server$(async function () {
  return 'ok';
});

export async function emitViewContent() {
  return emitViewContentServer();
}

Before, the router generated only:

import './emit-view-content';
Rollup could tree-shake that away. Now it keeps the module exports live.

@Varixo Varixo self-assigned this Jul 9, 2026
@Varixo Varixo requested a review from a team as a code owner July 9, 2026 15:09
@Varixo Varixo added the V2 label Jul 9, 2026
@changeset-bot

changeset-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 572f492

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@qwik.dev/router Patch
eslint-plugin-qwik Patch
@qwik.dev/core Patch
create-qwik Patch
@qwik.dev/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@maiieul maiieul moved this from Backlog to Waiting For Review in Qwik Development Jul 9, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@8818

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@8818

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@8818

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@8818

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@8818

@qwik.dev/devtools

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/devtools@8818

commit: 572f492

@Varixo Varixo force-pushed the v2-fix-serverfn-discovery branch from a40dcf2 to 5316382 Compare July 9, 2026 15:23
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 572f492

@wmertens wmertens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🏌️

@wmertens wmertens merged commit 3176945 into build/v2 Jul 9, 2026
48 checks passed
@wmertens wmertens deleted the v2-fix-serverfn-discovery branch July 9, 2026 18:23
@github-project-automation github-project-automation Bot moved this from Waiting For Review to Done in Qwik Development Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants