fix(scaffold): drop the previous generator's missing-tool warning when another generator is chosen

The New Project dialog kept the last generator's requirement check until the next one returned, after a 300 ms debounce, so choosing Hono after Odin briefly said odin is not installed. The check results now carry their generator and only the chosen generator's are shown.
Цей коміт міститься в:
l0ng-ai committed 2026-12-06 04:26:09 +08:00
1 джерело 201ab6f54b
коміт ec658df596
2 files changed
+28 -5

No files matched your search

+8 -4
Переглянути файл
@@ -351,7 +351,11 @@ export function NewProjectDialog({
const [edited, setEdited] = useState<Record<string, Values>>({});
const [dynamic, setDynamic] = useState<{ id: string; key: string; fields: Field[] } | null>(null);
const [dynamicError, setDynamicError] = useState<string | null>(null);
const [requirements, setRequirements] = useState<Requirement[]>([]);
// Tagged with their generator, so another generator's warnings don't linger until its own check returns.
const [requirements, setRequirements] = useState<{ generator: string; list: Requirement[] }>({
generator: "",
list: [],
});
/** Installed SDKs by kind, once detected. */
const [sdks, setSdks] = useState<Partial<Record<string, Sdk[]>>>({});
const detecting = useRef(new Set<string>());
@@ -427,8 +431,8 @@ export function NewProjectDialog({
let live = true;
const timer = setTimeout(() => {
call(commands.scaffoldRequirements(generator.id, JSON.parse(valuesKey) as Values))
.then((r) => live && setRequirements(r))
.catch(() => live && setRequirements([]));
.then((list) => live && setRequirements({ generator: generator.id, list }))
.catch(() => live && setRequirements({ generator: generator.id, list: [] }));
}, 300);
return () => {
live = false;
@@ -492,7 +496,7 @@ export function NewProjectDialog({
}, [path]);
const visibleFields = fields.filter((f) => isVisible(f, values));
const invalidField = visibleFields.find((f) => fieldError(f, values[f.id] ?? ""));
const missing = requirements.filter((r) => !r.satisfied);
const missing = requirements.generator === generator?.id ? requirements.list.filter((r) => !r.satisfied) : [];
const loadingDynamic = !!generator?.dynamic && !dynamicFields.length && !dynamicError;
const invalid =
!generator || !!nameError || !location.trim() || !!invalidField || missing.length > 0 || loadingDynamic;
+20 -1
Переглянути файл
@@ -11,6 +11,7 @@ const mocks = vi.hoisted(() => ({
detect: vi.fn(),
tauri: false,
xcodeIcon: vi.fn(),
requirements: vi.fn(),
}));
const empty: GeneratorInfo = {
id: "empty",
@@ -93,7 +94,7 @@ vi.mock("@/platform/ipc", async (original) => {
...actual.commands,
scaffoldCatalog: () => Promise.resolve([empty, dotnet, appleApp, appleFramework]),
sdkDetect: mocks.detect,
scaffoldRequirements: () => Promise.resolve({ status: "ok", data: [] }),
scaffoldRequirements: mocks.requirements,
scaffoldFreeName: mocks.freeName,
scaffoldTargetTaken: mocks.taken,
scaffoldCreate: mocks.create,
@@ -107,6 +108,9 @@ vi.mock("../windows", async (original) => ({
}));
const ok = <T,>(data: T) => Promise.resolve({ status: "ok" as const, data });
beforeEach(() => {
mocks.requirements.mockImplementation(() => ok([]));
});
const nameInput = () => screen.getByLabelText("Name:");
const createButton = () => screen.getByRole("button", { name: "Create" });
@@ -124,6 +128,21 @@ describe("File › New Project… name and location", () => {
localStorage.clear();
});
it("drops the previous generator's missing-tool warning as soon as another generator is chosen", async () => {
let pending = false;
mocks.requirements.mockImplementation((id: string) => {
if (id !== "dotnet") return pending ? new Promise(() => {}) : ok([]);
return ok([{ program: "dotnet", min: null, found: null, satisfied: false, hint: "" }]);
});
render(<NewProjectOverlay />);
act(() => showNewProject());
fireEvent.click(await screen.findByRole("option", { name: ".NET" }));
expect(await screen.findByText(/dotnet is not installed/)).toBeInTheDocument();
pending = true;
fireEvent.click(screen.getByRole("option", { name: "Empty Project" }));
expect(screen.queryByText(/dotnet is not installed/)).toBeNull();
});
it("starts where the last project was created, named after the first free untitled folder", async () => {
render(<NewProjectOverlay />);
act(() => showNewProject());