solidjs / solidjs/solid-vite-plugin

@solidjs/testing-library resolves @solidjs/web to the server build (isServer true) in jsdom tests under a multi-project vitest setup

未关闭
#369 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
TypeScript
星标
520
派生
70
平均合并
23 小时 35 分钟
30 天内合并 PR
39

描述

Environment

  • @solidjs/vite-plugin 3.0.0-next.44
  • vitest 5.0.1, multi-project (projects), pool: threads, isolate: false
  • solid-js / @solidjs/web 2.0.0-rc.9
  • @solidjs/testing-library 1.0.0-beta.3

Reproduction

A vitest config with two projects, one jsdom ("client") and one node ("server"):

test: {
  projects: [
    { test: { name: "client", environment: "jsdom", include: ["src/**/*.test.tsx"] } },
    { test: { name: "server", environment: "node", include: ["src/server/**/*.test.ts"] } },
  ],
}

In a test file, import { isServer } from "@solidjs/web" is false (correct browser build). But inside @solidjs/testing-library's render, @solidjs/web is the server build (isServer === true), so render/hydrate behave incorrectly.

Root cause

In the client/jsdom test posture the plugin injects browser into resolve.conditions (fixing inlined modules) but leaves @solidjs/web and @solidjs/testing-library externalized — and explicitly externalizes solid-js via test.server.deps.external: [/solid-js/]. Externalized modules are executed natively by Node, whose resolution conditions are ['node', 'import', 'default'] (no browser). So @solidjs/testing-library's own import { render, hydrate } from "@solidjs/web" resolves the node export (dist/server.js).

The plugin already handles the inverse case for the node/server posture by inlining /solid-js/ + /@solidjs[+/]web/, but the client posture gets no equivalent treatment.

Workaround

Inline the runtime packages so their imports resolve through Vite's browser condition:

test: {
  server: {
    deps: {
      inline: ["solid-js", "@solidjs/web", "@solidjs/testing-library"],
    },
  },
}

(deps.inline takes precedence over deps.external.)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从插件针对 node/server 变体的依赖处理开始,并将其与 issue 中描述的 client/jsdom 路径进行比较。复现 multi-project Vitest 配置,然后验证 render 和 hydrate 是否能解析 browser build,而无需 workaround。

由索引模型根据 Issue 内容生成。

评估

技术栈
node.js, typescript, vite
领域
build-system, testing-qa
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
活跃
描述清晰度
描述清楚
新手友好度
68/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。