microts: a compiled model that only a type import reaches is generated for the AOT build and absent from the guest bundle

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

还没有人认领这个 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 内容生成。

描述

bug

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,通用步骤见我们的新手贡献指南。

从这里开始

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

pocket-stack/pocketjs 的其他 Issue

查看 pocket-stack/pocketjs 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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