microts: a compiled model that only a type import reaches is generated for the AOT build and absent from the guest bundle
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust, typescript
- 领域
- compilers
调研方向
Start in microts/compiler/aot-model-view.ts at analyzeViewModel, which selects the root model by file name and accepts a type-only import as evidence. Run the two tools/pocket.ts compile commands from the repro and compare gen/app_model.rs with the guest bundle to see where the module graph loses app.ts. The fix is to make the guest build load the same root model or make the compiler reject a model reached only by a type import, while keeping type-only models like apps/hero/app.ts accepted.
由索引模型根据 Issue 内容生成。
描述
Version
PocketJS main (2c9fcf30). macOS 27.2 arm64, Bun 1.4.2.
Repro
pocket.host.json, pocket.host.config.ts (aot: true, model: "compiled") and main.tsx as in #720.
// app.ts
import { createSignal } from "solid-js";
import { createEffect, on } from "@pocketjs/framework/solid/reactive";
import type { i32 } from "@pocketjs/framework/solid/std";
export interface AppProps {
title?: string;
}
export const [ticks, setTicks] = createSignal<i32>(0);
export const [doubled, setDoubled] = createSignal<i32>(0);
createEffect(on([ticks], () => {
setDoubled(ticks() * 2);
}));
export function tick(): void {
setTicks(ticks() + 1);
}
// app.tsx
import { Text, View } from "@pocketjs/framework/solid/components";
import type { AppProps } from "./app";
export default function App(props: AppProps) {
return (
<View class="w-full h-full p-4 bg-slate-100">
<Text class="text-lg text-slate-900">{props.title ?? "Hello"}</Text>
</View>
);
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --output out/app.pkb
Actual
Both builds succeed and disagree about the model:
| Build | Model |
|---|---|
--aot |
gen/app_model.rs (145 lines) holds both signals, the effect and tick |
| guest | dist/repro.js has no app.ts module and no tick |
With import { doubled, type AppProps } from "./app"; and {doubled()} in the view, the guest bundle holds the app.ts module and exports tick.
In the AOT build the effect runs and a Rust host can call tick; in the guest build the same application has no model.
Expected
The two builds agree. Either the guest build loads the root model of a model: "compiled" application whenever the AOT build generates it, or the compiler reports a root model that declares state, effects or functions and that no value import reaches. A model that declares only types, as apps/hero/app.ts does, stays accepted.
Cause
TypeScript and the bundler erase a type-only import, so the guest module graph has no edge to app.ts. analyzeViewModel (microts/compiler/aot-model-view.ts) selects the root model by file name and analyzes it whenever the views' TypeScript program holds the file, which a type-only import satisfies.
#737 reports the case where no view imports the model at all (app.tsx does not import its model app.ts).
Workaround
Import a value from the model in a view and read it.
- 主要语言
- TypeScript
- 星标
- 1.6k
- 派生
- 88
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pocket-stack/pocketjs 的其他 Issue
-
microts: a model local that every branch assigns raises unused_assignments in the generated Rust未关闭bug
难度 2/5 1-3 小时 新手友好度 80/100
pocket-stack/pocketjs#756 ·
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
pocket-stack/pocketjs#746 ·
-
bug
难度 1/5 1 小时以内 新手友好度 88/100
pocket-stack/pocketjs#745 ·
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
pocket-stack/pocketjs#743 ·
-
bug
难度 5/5 一周以上 新手友好度 12/100
pocket-stack/pocketjs#757 ·
查看 pocket-stack/pocketjs 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
security: set top-level least-privilege permissions in five workflows可能已有人在做 @JonathanTSilva 今天认领。 未关闭priority: p2 size: xs type: security
难度 2/5 1-3 小时 新手友好度 64/100
JonathanTSilva/jts-website#150 ·
维护者通常 1 天内回复
-
bug Needs Triage
难度 2/5 1-3 小时 新手友好度 82/100
scottbenton/Iron-Link#437 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
speakeasy-api/speakeasy#2159 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
vercel-labs/ui#1066 ·
维护者通常 1 天内回复