Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Define `__SOLID_SERVER_COMPONENTS__` at build time so libraries can drop server-component-only client code

Đã đóng
#396 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rollup, typescript, vite
Lĩnh vực
build-system

Hướng nghiên cứu

Start in the main plugin's config() hook, next to the existing optimizeDeps.rolldownOptions.transform.jsx, and trace how serverFunctions.components and user define values are resolved. Add the constant in both requested define locations and cover the true, false, and user-provided cases; update the RFC 11 integration surface and server-components skill docs. Done when the checklist is covered and plugin tests pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

@solidjs/router ships a client fallback for server-component forms. These forms arrive as URLs in the HTML with no client reference. When no action() handler is installed, the router intercepts POSTs under actionBase and lazily imports its action layer.

Only server-component apps need this, but every router app pays for it. In a minimal router app with no server functions (Vite 8, gzip):

  • about 0.85 KB eager (up to 1.4 KB when it's the app's only dynamic import);
  • a 16.8 KB lazy chain: the serverForms chunk (8.6 KB) plus the decode chunk (7.0 KB) and a server chunk (1.2 KB) behind it.

The router's flat build inlines all of it eagerly (about 8 KB).

Proposal

The plugin defines a global constant __SOLID_SERVER_COMPONENTS__. Core owns and documents the name, with the meaning "server components are enabled for this build".

  • Value: true when serverFunctions.components is truthy (including 'external'), otherwise false. It must always be defined: if it's left undefined, nothing can be removed.
  • Set it in both top-level define (build, and dev source via /@vite/env) and optimizeDeps.rolldownOptions.transform.define (dev pre-bundled dependencies; the optimizer ignores top-level define).
  • Respect a user-provided define[__SOLID_SERVER_COMPONENTS__].
  • Applying it to all environments is fine; it's harmless on the server.

Why a define

Whether a check folds away depends on the form:

Form Rollup Rolldown 1.2.6 esbuild
Imported, never-written let flag folds doesn't fold doesn't fold
Literal define folds folds folds

Cost

Zero for apps. One config entry in the plugin.

Router follow-up

declare const __SOLID_SERVER_COMPONENTS__: boolean | undefined;
if (typeof __SOLID_SERVER_COMPONENTS__ !== "undefined" && __SOLID_SERVER_COMPONENTS__) {
  /* intercept */ import("./serverForms.js")...
}
Bundler, solid entry today, KB gz eager / lazy with false
Rolldown 18.84 / 16.22 17.97 / 0
Rollup 19.74 / 15.22 18.94 / 0
esbuild 22.62 eager, serverForms lazy 20.95, serverForms gone
  • With true, output matches today and serverForms stays lazy, so server-component apps without action() still don't pay for it eagerly.
  • In the flat build, false saves about 7–8 KB eager.
  • The router's own build (tsc + Rollup) keeps the guard; no config change is needed.
  • Without the plugin, the fallback is off at runtime and the bytes are the same as today. Server-component setups without the plugin define the constant themselves, as documented in core.

Alternatives considered

  • configureClient setup modules: too much wiring through start mode.
  • A runtime flag in server-functions/frames: doesn't fold under Rolldown or esbuild (measured above).
  • The router installing the fallback from serverRouteComponent/action: leaves a coverage gap, because forms can arrive with neither present.
  • Asking Rolldown upstream to fold imported constants: out of our control.

Implementation sketch

This goes in the main plugin's config() hook, next to the existing optimizeDeps.rolldownOptions.transform.jsx, using the serverFunctions.components value resolved in solidPlugin().

const SC_KEY = "__SOLID_SERVER_COMPONENTS__";
// inside config():
const scDefine = { [SC_KEY]: userConfig.define?.[SC_KEY] ?? JSON.stringify(serverComponents) };
return {
  define: scDefine,
  optimizeDeps: {
    // ...existing
    rolldownOptions: { transform: { jsx: { runtime: "classic" }, define: scDefine }, plugins: [/* existing */] }
  }
};

Checklist

  • Plugin: define plus optimizeDeps.rolldownOptions.transform.define; respect the user's value.
  • Core docs: RFC 11 integration surface and the server-components skill (cross-link).
  • Router: wrapped guard; vitest define true plus an off-path test; changeset.
Ngôn ngữ chính
TypeScript
Star
522
Fork
72
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
38

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solidjs/solid-vite-plugin

Tất cả issue của solidjs/solid-vite-plugin

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.