Skip to content

fix(viewer): support variable and unicode filenames in OpenSCAD import and auto-hydrate mesh storage - #260

Open
MARYCOMPLEX wants to merge 4 commits into
Adam-CAD:masterfrom
MARYCOMPLEX:fix/openscad-import-filenames
Open

fix(viewer): support variable and unicode filenames in OpenSCAD import and auto-hydrate mesh storage#260
MARYCOMPLEX wants to merge 4 commits into
Adam-CAD:masterfrom
MARYCOMPLEX:fix/openscad-import-filenames

Conversation

@MARYCOMPLEX

@MARYCOMPLEX MARYCOMPLEX commented Sep 4, 2026

Copy link
Copy Markdown

Summary

Fixes an issue where uploaded 3D mesh files imported in OpenSCAD code fail to render under two common scenarios:

  1. Variable & Unicode Filename Extraction:
    Previously, extractImportFilenames used a rigid regex /import\s*\(\s*"([^"]+)"\s*\)/g which only matched hardcoded ASCII literal strings. When models generated code using variable references (e.g. model_file = "model.stl"; import(model_file);) or non-ASCII / Unicode filenames (e.g. 牛来修.stl), extractImportFilenames returned empty, causing OpenSCAD to fail with Can't open import file.

    • Updated extractImportFilenames to support direct string literals (single/double quotes), variable assignments, and fallback regex for 3D/drawing assets.
  2. Supabase Mesh Storage Auto-Hydration:
    Previously, MeshFilesContext only held mesh files in memory after initial drag/drop. If the user refreshed the page or navigated directly to /editor/:id, the in-memory map was empty and prepareMeshFiles did not fetch the uploaded mesh from Supabase Storage.

    • Added automatic mesh hydration on conversation load in EditorView.
    • Added fallback download in prepareMeshFiles in OpenSCADViewer to ensure mesh files are seamlessly fetched from Supabase storage and written to the OpenSCAD worker filesystem.

Testing

  • Verified with unit & compilation checks (`npm run typecheck` passes).
  • Verified variable `import(model_file)` and unicode mesh filenames render correctly in OpenSCAD viewer.
  • Verified page refresh and direct URL navigation properly download and compile imported mesh files.

Summary by cubic

Fixes the OpenSCAD viewer import to support variable and Unicode filenames, and auto-hydrates mesh files from Supabase storage when a conversation loads. Previously, filenames with non-ASCII characters or dynamic variables could fail during import, and stored meshes weren't restored after page refresh or direct URL navigation, forcing re-uploads.

  • Mesh attachments are scoped by conversationId in MeshFilesContext to prevent cross-conversation collisions.
  • Storage download logic moved to meshService.ts so OpenSCADViewer stays free of network and DB calls.
  • Recompilation is reactive but scoped: the filesVersion counter triggers a rebuild only when the code changed or a required mesh file was newly written.
  • Variable imports require identifier boundaries and regex escaping to prevent substring collisions.

Written for commit fbdfb0a. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Adam Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR expands OpenSCAD import filename extraction and restores persisted mesh attachments into conversation-scoped browser storage.

  • Supports direct, variable-based, and Unicode mesh references in OpenSCAD source.
  • Scopes cached mesh blobs by conversation and recompiles after hydration.
  • Centralizes persisted attachment extraction and mesh downloading in a mesh service.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains.

No blocking failure remains.

Important Files Changed

Filename Overview
src/components/viewer/OpenSCADViewer.tsx Expands import extraction, uses conversation-scoped mesh lookup, and recompiles when hydrated files are written.
src/contexts/MeshFilesContext.tsx Adds conversation-qualified cache keys, canonical basename lookup, targeted clearing, and a reactive file version.
src/services/meshService.ts Converts persisted message parts into mesh attachment descriptors and provides attachment download behavior.
src/views/EditorView.tsx Hydrates conversation mesh attachments into the scoped in-memory workspace when messages load.
src/components/TextAreaChat.tsx Stores uploaded STL blobs under both their original filename and generated storage filename within the conversation scope.

Reviews (4): Last reviewed commit: "perf: scope recompile trigger to code ch..." | Re-trigger Greptile

Comment thread src/views/EditorView.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/views/EditorView.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx Outdated
- Extract Supabase storage download logic into meshService.ts
- Scope MeshFilesContext cache by conversationId to prevent cross-conversation collisions
- Parse mesh attachments via messageRowToChatMessage and AppUIMessage canonical types
- Keep OpenSCADViewer purely presentational and free of direct network/DB calls
Comment thread src/contexts/MeshFilesContext.tsx

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/contexts/MeshFilesContext.tsx Outdated
Comment thread src/components/viewer/OpenSCADViewer.tsx
…ration, and regex identifier boundaries

- Eliminate global fallback in MeshFilesContext to prevent cross-conversation mesh collisions
- Expose reactive filesVersion from MeshFilesContext so OpenSCADViewer re-prepares and compiles on async hydration
- Require identifier boundaries and regex escaping for variable-bound OpenSCAD imports

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread src/components/viewer/OpenSCADViewer.tsx
…ted meshes

- Return hasNewWrites from prepareMeshFiles
- Skip recompilation on filesVersion changes when scadCode has no imports or no new required files were written
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant