From 9c9e46268222ae3972de97c73ef476839ffdedd6 Mon Sep 17 00:00:00 2001 From: 134 Date: Mon, 27 Jul 2026 20:45:16 +0800 Subject: [PATCH] feat: restore isolated HiCAD engineering tools --- app/(chat)/ai-cad/page.tsx | 2 +- scripts/vendor-zoo-modeling-app.mjs | 22 ++++++++-- .../hicad-manufacturing-extension.test.ts | 13 +++++- .../HicadManufacturingSlot.tsx.template | 40 +++++++++++++++++++ 4 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template diff --git a/app/(chat)/ai-cad/page.tsx b/app/(chat)/ai-cad/page.tsx index 54294f17d..42a73be8c 100644 --- a/app/(chat)/ai-cad/page.tsx +++ b/app/(chat)/ai-cad/page.tsx @@ -5,7 +5,7 @@ import { redirect } from "next/navigation"; import { auth } from "@/app/(auth)/auth"; const ZOO_MODELING_APP_SRC = - "/vendor/zoo-modeling-app/index.html?v=f2b345db"; + "/vendor/zoo-modeling-app/index.html?v=f2b345db-eng1"; export const dynamic = "force-dynamic"; export const metadata: Metadata = { diff --git a/scripts/vendor-zoo-modeling-app.mjs b/scripts/vendor-zoo-modeling-app.mjs index 3fa58cdd1..3046311d0 100644 --- a/scripts/vendor-zoo-modeling-app.mjs +++ b/scripts/vendor-zoo-modeling-app.mjs @@ -149,6 +149,10 @@ function patchOfficialSource() { path.join(customizationDir, "HicadManufacturingLauncher.tsx.template"), path.join(sourceDir, "src/components/HicadManufacturingLauncher.tsx") ); + copyFileSync( + path.join(customizationDir, "HicadManufacturingSlot.tsx.template"), + path.join(sourceDir, "src/components/HicadManufacturingSlot.tsx") + ); } copyFileSync( path.join(customizationDir, "localization.ts"), @@ -215,26 +219,36 @@ function patchOfficialSource() { " \n", "" ); + replaceSource( + "src/components/OpenedProject.tsx", + "import { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'\n", + "" + ); + replaceSource( + "src/components/OpenedProject.tsx", + " \n", + "" + ); if (enableManufacturingExtension) { replaceSource( "src/components/OpenedProject.tsx", "import { AppHeader } from '@src/components/AppHeader'\n", - "import { AppHeader } from '@src/components/AppHeader'\nimport { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'\n" + "import { AppHeader } from '@src/components/AppHeader'\nimport { HicadManufacturingSlot } from '@src/components/HicadManufacturingSlot'\n" ); replaceSource( "src/components/OpenedProject.tsx", " \n \n \n", + " \n", "" ); } diff --git a/tests/routes/hicad-manufacturing-extension.test.ts b/tests/routes/hicad-manufacturing-extension.test.ts index d086486d7..90c84de1b 100644 --- a/tests/routes/hicad-manufacturing-extension.test.ts +++ b/tests/routes/hicad-manufacturing-extension.test.ts @@ -53,11 +53,20 @@ test.describe('HiCAD manufacturing extension', () => { .at(-1) ) expect(vendorScript).toContain( - "import { HicadManufacturingLauncher } from '@src/components/HicadManufacturingLauncher'" + "import { HicadManufacturingSlot } from '@src/components/HicadManufacturingSlot'" ) expect(vendorScript).toContain( - "" + "" ) + const slot = fs.readFileSync( + path.join( + projectRoot, + 'vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template' + ), + 'utf8' + ) + expect(slot).toContain('lazy(() =>') + expect(slot).toContain('ManufacturingSlotBoundary') const launcher = fs.readFileSync( path.join( projectRoot, diff --git a/vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template b/vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template new file mode 100644 index 000000000..d9d9f170e --- /dev/null +++ b/vendor/zoo-modeling-app/HicadManufacturingSlot.tsx.template @@ -0,0 +1,40 @@ +import { Component, lazy, Suspense, type ErrorInfo, type ReactNode } from 'react' + +const ManufacturingLauncher = lazy(() => + import('./HicadManufacturingLauncher').then((module) => ({ + default: module.HicadManufacturingLauncher, + })) +) + +class ManufacturingSlotBoundary extends Component< + { children: ReactNode }, + { failed: boolean } +> { + state = { failed: false } + + static getDerivedStateFromError() { + return { failed: true } + } + + componentDidCatch(error: unknown, info: ErrorInfo) { + console.error('[HiCAD Manufacturing] Launcher failed safely', error, info) + } + + render() { + return this.state.failed ? null : this.props.children + } +} + +export function HicadManufacturingSlot({ + projectName, +}: { + projectName: string +}) { + return ( + + + + + + ) +}