Compile-time styling (StyleX) can't see styles declared in .rx: imports are aliased and top-level bindings live inside the module factory

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
typescript
领域
build-system

调研方向

Read the @solidjs/vite-plugin frontend transform hook and the compiler output that aliases imports and moves top-level declarations into the module factory. Check whether the proposed module-scope form can be emitted for .rx and then seen by a compile-time styling plugin. Done means the issue’s question is resolved, with either a supported integration path or documentation of the sibling .ts workaround in guide/libraries.md.

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

描述

Compile-time styling libraries can't see styles written in .rx. StyleX is the case we hit; vanilla-extract, Panda and similar tools have the same constraint.

What happens

import pure { attrs, create } from "@stylexjs/stylex"

local = create({ hint: { color: "red" } })

export component Hint() {
  <p {...attrs(local.hint)}>hint</p>
}

rxc check passes. In the browser: Unexpected 'stylex.create' call at runtime. Styles must be compiled by '@stylexjs/babel-plugin', and Solid halts the reactive system (REACTIVITY_HALTED).

Why

Two things stack:

  1. No plugin sees the lowered code in time. @stylexjs/unplugin is enforce: 'pre' and only transforms JS-like ids. .rx becomes JS inside @solidjs/vite-plugin's transform (the frontends hook), after every pre plugin has already passed over the raw .rx text.
  2. Even if one did, the output isn't analyzable. Compile-time styling needs create({...}) at module top level, with literal arguments and the import binding used directly. The crate's output aliases every import (import { create as w$create } … const v$create = w$create) and moves every top-level declaration inside export default function module(__rt) { … }, where local is a __rt.memo.

Today's workaround (works)

Declare styles in a sibling .ts module and import the compiled object: import pure { s } from "./form.styles", then attrs(s.form, props.styles). Recipe functions from a StyleX design system (import pure { button } from "…/stylex/button") also work unchanged. We verified this end to end with SSR and hydration on Solid 2.0.0-rc.21, @solidjs/vite-plugin 3.0.0-next.57 and compiler/runtime 0.3.1.

Suggestion

  • A module-scope form that lowers verbatim. For example, a top-level binding whose right-hand side is a call to an imported pure function with literal arguments (or an explicit keyword) is emitted outside the module factory, and the import it calls stays unaliased. Styling compilers could then process .rx output the way they process .tsx.
  • Plugin ordering, in @solidjs/vite-plugin. Let other plugins see a frontend's lowered JS. For example, lower in load, or document a hook point a styling plugin can run after. This depends on the first point; on its own it doesn't help.

Is compile-time CSS-in-JS a goal for .rx? Or is the scoped <style> (spec/07 CSS-1…5) the intended answer, with a sibling .ts for StyleX? Either answer is useful; if the latter, a line in guide/libraries.md would save the next person the runtime crash.

主要语言
TypeScript
星标
127
派生
7
平均合并
15 小时 42 分钟
30 天内合并 PR
63

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

solidjs/reactivescript 的其他 Issue

查看 solidjs/reactivescript 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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