Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(viewer): honest pending state, invitation-style empty state, flash fixes

Sidwebworksdaaddf5a8512
diff --git a/apps/erp/app/components/CadModel.tsx b/apps/erp/app/components/CadModel.tsx
index e9660fe7e2..513a04ad95 100644
--- a/apps/erp/app/components/CadModel.tsx
+++ b/apps/erp/app/components/CadModel.tsx
@@ -23,7 +23,7 @@ import {
MODEL_RAW_KEEP_MAX_BYTES,
supportedModelTypes
} from "@carbon/utils";
-import { ModelPreview } from "@carbon/viewer/model-preview";
+import { ModelPreview, WASM_RAW_ENABLED } from "@carbon/viewer/model-preview";
import { nanoid } from "nanoid";
import { useEffect, useId, useRef, useState } from "react";
import { useDropzone } from "react-dropzone";
@@ -105,6 +105,20 @@ function useModelArtifacts(modelPath: string | null): {
const [pending, setPending] = useState(true);
const [reloadKey, setReloadKey] = useState(0);
+ // `pending` must mean "a GLB is genuinely on its way", not "still checking":
+ // the viewer renders it as an optimise-in-progress spinner, so a settled
+ // model must not wear it for a grace window. Settle on the first response
+ // unless the status is actually in flight; the background polling below
+ // still catches a later transition (fresh upload flipping to Processing)
+ // and re-raises pending then.
+ useEffect(() => {
+ const data = fetcher.data;
+ if (!data) return;
+ const inFlight =
+ data.optimizeStatus === "Queued" || data.optimizeStatus === "Processing";
+ setPending(inFlight && !(data.optimizedModelPath || data.glbPath));
+ }, [fetcher.data]);
+
// biome-ignore lint/correctness/useExhaustiveDependencies: reloadKey re-runs the effect on retry without being read inside it
useEffect(() => {
if (!modelUploadId) {
@@ -128,7 +142,8 @@ function useModelArtifacts(modelPath: string | null): {
data?.optimizeStatus === "Queued" ||
data?.optimizeStatus === "Processing";
// `Idle`/undefined is the brief window before the job starts (or a non-mesh
- // upload that never optimises) — poll it only for a short grace period.
+ // upload that never optimises) — keep polling quietly for a grace period
+ // (pending is driven by the data effect above, not this loop).
const cap = inFlight ? 60 : 8; // ~3min in flight vs ~24s settling
attempts += 1;
if (attempts > cap) {
@@ -197,18 +212,38 @@ const CadModel = ({
const hasInteractive = Boolean(
artifacts?.optimizedModelPath || artifacts?.glbPath
);
- const rawRenderable = Boolean(
- (artifacts?.rawPath && (artifacts.size ?? 0) <= MODEL_RAW_KEEP_MAX_BYTES) ||
- (file && file.size <= MODEL_RAW_KEEP_MAX_BYTES)
- );
+ const rawRenderable =
+ WASM_RAW_ENABLED &&
+ Boolean(
+ (artifacts?.rawPath &&
+ (artifacts.size ?? 0) <= MODEL_RAW_KEEP_MAX_BYTES) ||
+ (file && file.size <= MODEL_RAW_KEEP_MAX_BYTES)
+ );
// Staged progress overlay: an optimise is running and nothing else can
// render (no artifact yet, raw too big / absent). When the raw tier renders,
// the optimise runs silently behind it and the GLB swaps in on success.
const optimizeInFlight =
artifacts?.optimizeStatus === "Queued" ||
artifacts?.optimizeStatus === "Processing";
+ // Bridges the click -> job-visible gap: the row status takes a couple of
+ // polls to flip after Load Preview / Retry, and without this the overlay
+ // wouldn't appear until then. Cleared on handover (or a 15s safety timeout
+ // if the trigger silently failed).
+ const [optimisticOptimize, setOptimisticOptimize] = useState(false);
+ useEffect(() => {
+ if (!optimisticOptimize) return;
+ if (optimizeInFlight || hasInteractive) {
+ setOptimisticOptimize(false);
+ return;
+ }
+ const timeout = setTimeout(() => setOptimisticOptimize(false), 15000);
+ return () => clearTimeout(timeout);
+ }, [optimisticOptimize, optimizeInFlight, hasInteractive]);
const showOptimizeProgress =
- optimizeInFlight && !hasInteractive && !rawRenderable && upload === null;
+ (optimizeInFlight || optimisticOptimize) &&
+ !hasInteractive &&
+ !rawRenderable &&
+ upload === null;
const onDelete = async () => {
if (!carbon) {
@@ -274,6 +309,7 @@ const CadModel = ({
const onRetry = () => {
const modelUploadId = modelIdFromPath(modelPath);
if (isReadOnly || !modelUploadId) return;
+ setOptimisticOptimize(true);
reoptimizeFetcher.submit(
{ modelUploadId },
{ method: "post", action: path.to.api.modelReoptimize }
@@ -401,6 +437,11 @@ const CadModel = ({
? "Retry"
: "Load Preview"
}
+ settledHint={
+ artifacts?.optimizeStatus === "Failed"
+ ? "The last attempt didn't finish. You can try again."
+ : undefined
+ }
onCancelWait={modelPath ? onCancelWait : undefined}
onDelete={canDelete ? deleteModal.onOpen : undefined}
/>
@@ -419,7 +460,7 @@ const CadModel = ({
<ModelOptimizeProgress
key={`${modelPath}:${artifacts?.optimizeStatus}`}
modelUploadId={modelIdFromPath(modelPath) ?? ""}
- queued={artifacts?.optimizeStatus === "Queued"}
+ queued={artifacts?.optimizeStatus !== "Processing"}
/>
</div>
)}
diff --git a/packages/viewer/src/AssemblyViewer.tsx b/packages/viewer/src/AssemblyViewer.tsx
index 1e66e83eae..562ca2a445 100644
--- a/packages/viewer/src/AssemblyViewer.tsx
+++ b/packages/viewer/src/AssemblyViewer.tsx
@@ -57,7 +57,14 @@ export function AssemblyViewer({
far: 100000
}}
resize={{ debounce: 0 }}
- style={{ position: "absolute", inset: 0 }}
+ // Explicit CSS background on the canvas element: with alpha:true the
+ // canvas layer is otherwise transparent, and Chrome's recomposite
+ // during page unload/reload flashes such layers white in dark mode.
+ style={{
+ position: "absolute",
+ inset: 0,
+ background: isDarkMode ? "#141619" : "#ffffff"
+ }}
>
<ambientLight intensity={isDarkMode ? 0.6 : 0.8} />
<hemisphereLight
diff --git a/packages/viewer/src/ModelPreview.tsx b/packages/viewer/src/ModelPreview.tsx
index 5efca454f0..3c8cd86d0c 100644
--- a/packages/viewer/src/ModelPreview.tsx
+++ b/packages/viewer/src/ModelPreview.tsx
@@ -1,10 +1,10 @@
-import { cn, IconButton } from "@carbon/react";
+import { Button, cn, IconButton } from "@carbon/react";
import { lazy, Suspense, useEffect, useMemo, useRef, useState } from "react";
import {
+ LuBox,
LuChevronDown,
LuDownload,
LuMaximize,
- LuRotateCw,
LuTrash2
} from "react-icons/lu";
import type { ModelMetrics } from "./ModelCanvas";
@@ -22,7 +22,10 @@ const ModelCanvas = lazy(() =>
// assembler artifacts opts out with VITE_CAD_VIEWER_USE_SERVER=true, and the
// exact `import.meta.env.X` form is statically replaced by Vite so the whole
// tier — occt WASM included — is then dead-code-eliminated from the build.
-const WASM_RAW_ENABLED = import.meta.env.VITE_CAD_VIEWER_USE_SERVER !== "true";
+// Exported so hosts can align their fallback logic (e.g. CadModel only treats
+// a small raw as renderable when the tier actually shipped in this build).
+export const WASM_RAW_ENABLED =
+ import.meta.env.VITE_CAD_VIEWER_USE_SERVER !== "true";
const RawModelCanvas = WASM_RAW_ENABLED
? lazy(() =>
import("./raw/RawModelCanvas").then((m) => ({
@@ -56,6 +59,9 @@ export type ModelPreviewProps = {
/** Label for the retry action — e.g. "Load Preview" when the model was never
* optimised (first-time affordance) vs the default "Retry" after a failure. */
retryLabel?: string;
+ /** Supporting line under the settled-state title — the host can explain a
+ * failed attempt; defaults to the generate-on-demand invitation. */
+ settledHint?: string;
/** Called when the user cancels the "preparing" wait — the host should cancel
* the in-flight optimise (job + run) so the row doesn't stay stuck. */
onCancelWait?: () => void;
@@ -67,11 +73,11 @@ export type ModelPreviewProps = {
/**
* Progressive model preview. Renders the assembler's artifacts with three.js
* (`ModelCanvas`): the single-draw LOD paints instantly, the full optimised GLB
- * cross-fades in on top. When there is no server GLB it shows a spinner (while
- * one may still arrive) or a "preview unavailable" notice — there is no
- * in-browser tessellation fallback. The renderer is lazy-imported and only
- * mounts once the viewer scrolls into view. Chrome: dimensions/properties, unit
- * toggle, download, reset view, click-to-interact.
+ * cross-fades in on top. With no server GLB the raw (WASM) tier renders the
+ * original upload in-browser; failing that, a cancellable preparing state
+ * (optimise in flight) or a generate-on-demand invitation. The renderer is
+ * lazy-imported and only mounts once the viewer scrolls into view. Chrome:
+ * dimensions/properties, unit toggle, download, reset view, click-to-interact.
*/
export function ModelPreview({
awaitingModel = false,
@@ -84,6 +90,7 @@ export function ModelPreview({
downloadName,
onRetry,
retryLabel = "Retry",
+ settledHint,
onCancelWait,
mode = "dark",
onDelete,
@@ -132,8 +139,10 @@ export function ModelPreview({
>
{hasServerModel || useRawTier ? (
<>
- {/* Tier 0: instant poster — thumbnail image while the 3D boots. */}
- {thumbnailUrl && !fullLoaded && (
+ {/* Tier 0: instant poster — thumbnail image while the 3D boots.
+ Light mode only: the generated PNGs have an opaque white
+ background, which reads as a white flash on a dark viewer. */}
+ {thumbnailUrl && !fullLoaded && mode === "light" && (
<img
src={thumbnailUrl}
alt=""
@@ -270,22 +279,25 @@ export function ModelPreview({
</button>
</div>
) : inView ? (
- // Settled with no server GLB (optimise failed / non-mesh). No in-browser
- // tessellation fallback — surface the state instead of a dead spinner.
- <div className="absolute inset-0 flex flex-col items-center justify-center gap-3 p-4 text-center">
- <p className="text-sm text-muted-foreground">
- 3D preview unavailable
- </p>
+ // Settled with no renderable tier. Framed as an invitation, not a
+ // failure: the preview simply hasn't been generated yet (or the raw is
+ // over the in-browser cap) — the primary action generates it on demand.
+ <div className="absolute inset-0 flex flex-col items-center justify-center gap-4 p-4 text-center">
+ <div className="flex size-11 items-center justify-center rounded-full bg-muted/60">
+ <LuBox className="size-5 text-muted-foreground" />
+ </div>
+ <div className="flex flex-col gap-1">
+ <p className="text-sm font-medium text-foreground">3D preview</p>
+ <p className="max-w-[240px] text-xs text-pretty text-muted-foreground">
+ {settledHint ??
+ "Generate an interactive view of this model on demand."}
+ </p>
+ </div>
<div className="flex items-center gap-2">
{onRetry && (
- <button
- type="button"
- onClick={onRetry}
- className="flex items-center gap-1.5 rounded-md border border-border bg-popover px-3 py-1.5 text-xs font-medium text-foreground shadow-sm transition-transform hover:bg-accent active:scale-[0.96]"
- >
- <LuRotateCw className="size-3.5" />
+ <Button size="sm" onClick={onRetry}>
{retryLabel}
- </button>
+ </Button>
)}
{onDelete && (
<IconButton