Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
stop a missing HDRI from taking the 3D mesh down with it (#4688)
[._.]/ Adam Eivyd7e37733ec6f
diff --git a/client/src/components/media/GlbViewer.jsx b/client/src/components/media/GlbViewer.jsxindex ff4242cb5d..071f8d2aaf 100644--- a/client/src/components/media/GlbViewer.jsx+++ b/client/src/components/media/GlbViewer.jsx@@ -9,6 +9,7 @@ import {import { AlertTriangle, Download, RefreshCw, Rotate3d, SlidersHorizontal } from 'lucide-react';import ErrorBoundary from '../ErrorBoundary';import { GltfPrimitive } from '../../hooks/useClonedGltf';+import { glbErrorText, glbFailureHint } from '../../lib/glbFailure';const DEFAULT_BACKGROUND = '#050505';const ENVIRONMENT_HDRI = '/hdri/studio-small-08-1k.hdr';@@ -76,31 +77,11 @@ function GlbModel({ src, forceOpaque }) {return <GltfPrimitive object={renderedScene} />;}-// One table so every recognized cause reads the same way. The raw messages are-// useless on their own: the glTF parser JSON.parses whatever bytes it is handed,-// so a 200 HTML body (an SPA fallback answering a path that isn't really-// served) surfaces as a JSON syntax error naming a `<` token.-const FAILURE_HINTS = [- [- /Unexpected token '<'|<!DOCTYPE/i,- 'The server answered with a web page instead of the mesh file — the asset may be missing or the server may still be restarting.',- ],- [/webgl/i, 'This display cannot create a WebGL context, so 3D previews cannot render here.'],- [/\b404\b|not found/i, 'The mesh file is no longer on disk.'],-];--const errorText = (error) => String(error?.message || error || '');--export function glbFailureHint(error) {- const message = errorText(error);- return FAILURE_HINTS.find(([pattern]) => pattern.test(message))?.[1] || null;-}-// r3f prefixes every loader failure with "Could not load <url>", so this is what// separates "the bytes never arrived" from a failure thrown after the mesh was// already parsed (context loss, a throw downstream of the load). Only the former// justifies evicting drei's cache on retry — see retryLoad.-const isLoadFailure = (error) => /^Could not load/i.test(errorText(error));+const isLoadFailure = (error) => /^Could not load/i.test(glbErrorText(error));function GlbLoadFailure({ error, onRetry }) {const hint = glbFailureHint(error);@@ -120,7 +101,7 @@ function GlbLoadFailure({ error, onRetry }) {<p className="text-sm font-medium">This 3D model could not be loaded</p>{hint && <p className="max-w-sm text-xs text-port-text-muted">{hint}</p>}<p className="max-w-full break-all font-mono text-[10px] leading-snug text-port-text-muted">- {errorText(error)}+ {glbErrorText(error)}</p><buttontype="button"@@ -264,15 +245,26 @@ export default function GlbViewer({<ambientLight intensity={ambientIntensity} /><directionalLight position={[4, 6, 5]} intensity={keyIntensity} /><directionalLight position={[-4, -2, -5]} intensity={fillIntensity} />+ {/* The HDRI gets its OWN boundary + Suspense, not the mesh's. Sharing+ one meant a missing or corrupt .hdr (a partial checkout, a stale+ service-worker cache) reported "This 3D model could not be+ loaded" and took the mesh down with it — while the file is only+ image-based LIGHTING, which the three lights below already+ stand in for. Same shape OpenWorldScene documents for its+ galaxy spheremap: degrade to lights-only, keep the scene. */}+ <ErrorBoundary fallback={null}>+ <Suspense fallback={null}>+ {/* Keep the HDRI in public/ instead of using drei's remote presets:+ preview lighting and the default backdrop must work offline. */}+ <Environment+ files={ENVIRONMENT_HDRI}+ background={showEnvironmentBackground}+ backgroundBlurriness={ENVIRONMENT_BACKGROUND_BLUR}+ />+ <EnvironmentIntensity value={environmentIntensity} reassertOn={showEnvironmentBackground} />+ </Suspense>+ </ErrorBoundary><Suspense fallback={null}>- {/* Keep the HDRI in public/ instead of using drei's remote presets:- preview lighting and the default backdrop must work offline. */}- <Environment- files={ENVIRONMENT_HDRI}- background={showEnvironmentBackground}- backgroundBlurriness={ENVIRONMENT_BACKGROUND_BLUR}- />- <EnvironmentIntensity value={environmentIntensity} reassertOn={showEnvironmentBackground} /><Bounds fit clip observe margin={1.2}><GlbModel src={src} forceOpaque={forceOpaque} /></Bounds>diff --git a/client/src/components/media/GlbViewer.test.jsx b/client/src/components/media/GlbViewer.test.jsxindex 81722f3fd3..46e455507d 100644--- a/client/src/components/media/GlbViewer.test.jsx+++ b/client/src/components/media/GlbViewer.test.jsx@@ -24,10 +24,15 @@ import { resolve } from 'node:path';// tell a working Retry from one that only looks like it re-fetched), while// `canvas.error` fails the CANVAS ITSELF, which is how r3f surfaces a WebGL// context failure: from its own render, with nothing cached to evict.-const { mockScene, gltf, canvas } = vi.hoisted(() => ({+// `hdri.error` fails the ENVIRONMENT only — a missing or corrupt .hdr (a partial+// checkout, a stale service-worker cache). It is deliberately separate from+// `gltf.error`: the whole point of the HDRI's own boundary is that the two+// failures must not produce the same outcome.+const { mockScene, gltf, canvas, hdri } = vi.hoisted(() => ({mockScene: {},gltf: { error: null, rejections: new Map() },canvas: { error: null },+ hdri: { error: null },}));vi.mock('@react-three/fiber', () => ({Canvas: ({ children }) => {@@ -39,7 +44,9 @@ vi.mock('@react-three/fiber', () => ({vi.mock('@react-three/drei', () => ({Canvas: () => null,OrbitControls: () => null,- Environment: ({ background, backgroundBlurriness, files, children }) => (+ Environment: ({ background, backgroundBlurriness, files, children }) => {+ if (hdri.error) throw hdri.error;+ return (<divdata-testid="glb-environment"data-background={background ? 'visible' : 'hidden'}@@ -48,7 +55,8 @@ vi.mock('@react-three/drei', () => ({>{children}</div>- ),+ );+ },Bounds: ({ children }) => children,useGLTF: Object.assign((url) => {if (gltf.error) gltf.rejections.set(url, gltf.error);@@ -60,7 +68,7 @@ vi.mock('@react-three/drei', () => ({vi.mock('../../hooks/useClonedGltf', () => ({ GltfPrimitive: () => null }));import { useGLTF } from '@react-three/drei';-import GlbViewer, { cloneGlbSceneWithOpaqueMaterials, glbFailureHint } from './GlbViewer';+import GlbViewer, { cloneGlbSceneWithOpaqueMaterials } from './GlbViewer';const openControls = () => fireEvent.click(screen.getByLabelText('Preview display settings'));@@ -68,6 +76,7 @@ beforeEach(() => {gltf.error = null;gltf.rejections.clear();canvas.error = null;+ hdri.error = null;useGLTF.clear.mockClear();});@@ -300,11 +309,40 @@ describe('GlbViewer load failures', () => {expect(useGLTF.clear).not.toHaveBeenCalled();expect(screen.getByTestId('glb-canvas')).toBeInTheDocument();});+});++describe('GlbViewer HDRI failures', () => {+ let logged;+ beforeEach(() => {+ logged = vi.spyOn(console, 'error').mockImplementation(() => {});+ vi.spyOn(console, 'warn').mockImplementation(() => {});+ });+ afterEach(() => { vi.restoreAllMocks(); });++ // The HDRI is image-based LIGHTING, which the three lights already stand in+ // for. Sharing the mesh's boundary meant a missing .hdr reported "This 3D+ // model could not be loaded" and took a perfectly good mesh down with it.+ it('degrades to lights-only when the HDRI fails, keeping the mesh', () => {+ hdri.error = new Error('Could not load /hdri/studio-small-08-1k.hdr: 404 Not Found');+ render(<GlbViewer src="/data/image-to-3d/abc/model.glb" />);- it('only names a cause it can actually recognize', () => {- expect(glbFailureHint(new Error('something went sideways'))).toBeNull();- expect(glbFailureHint(new Error('<!DOCTYPE html>'))).toMatch(/web page/i);- expect(glbFailureHint(new Error('responded with 404'))).toMatch(/no longer on disk/i);- expect(glbFailureHint(new Error('Error creating WebGL context'))).toMatch(/WebGL/i);+ expect(screen.queryByTestId('glb-load-error')).not.toBeInTheDocument();+ expect(screen.getByTestId('glb-canvas')).toBeInTheDocument();+ // The environment is the only thing gone — the viewer is NOT in failure+ // mode, so the controls driving the still-live canvas are still mounted.+ expect(screen.queryByTestId('glb-environment')).not.toBeInTheDocument();+ expect(screen.getByLabelText('Preview display settings')).toBeInTheDocument();+ openControls();+ expect(screen.getByLabelText('Ambient light')).toBeInTheDocument();+ expect(logged).toHaveBeenCalledWith(expect.stringContaining('💥 React Error'), expect.anything());+ });++ // The other half of the split: the mesh's own failure must still surface.+ it('still shows the failure panel when the MESH is what failed', () => {+ gltf.error = new Error('Could not load /data/image-to-3d/abc/model.glb: 404 Not Found');+ render(<GlbViewer src="/data/image-to-3d/abc/model.glb" />);++ expect(screen.getByTestId('glb-load-error')).toBeInTheDocument();+ expect(screen.queryByTestId('glb-canvas')).not.toBeInTheDocument();});});