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

Đang mở
#744 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, typescript
Lĩnh vực
compilers

Hướng nghiên cứu

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.

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

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
1.6k
Fork
88
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 pocket-stack/pocketjs

Tất cả issue của pocket-stack/pocketjs

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.