Skip to content

Cache repeated 3D model loads#882

Open
loong-solvable wants to merge 2 commits into
tscircuit:mainfrom
loong-solvable:fix-model-loader-cache-query-urls
Open

Cache repeated 3D model loads#882
loong-solvable wants to merge 2 commits into
tscircuit:mainfrom
loong-solvable:fix-model-loader-cache-query-urls

Conversation

@loong-solvable
Copy link
Copy Markdown

@loong-solvable loong-solvable commented May 12, 2026

/claim #93

Summary

  • Add normalized model URL helpers so .glb, .gltf, .obj, .stl, and .wrl URLs still resolve when they include query strings or hashes.
  • Cache load3DModel results by normalized URL, stripping only cachebust_origin, and reuse in-flight loads for duplicate model requests.
  • Return cloned model instances with cloned materials so hover/translucency state cannot leak between repeated components.
  • Route GltfModel through the shared loader while keeping a GLB fallback for extensionless GLTF/GLB endpoints.

Testing

  • npx biome check src/utils/load-model.ts src/three-components/GltfModel.tsx tests/load-model.test.ts
  • npx bun test tests/load-model.test.ts
  • npm run build
  • npx bun test currently has unrelated existing failures in tests/preprocess-circuit-json.test.ts faux-board z-offset expectations and tests/outline-bounds.test.ts Atari SVG color expectation; the new load-model tests pass.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
3d-viewer Ready Ready Preview, Comment May 15, 2026 8:56pm

Request Review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1b06d9cc2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/utils/load-model.ts Outdated
Comment on lines +11 to +12
function isAbsoluteUrl(url: string) {
return /^[a-z][a-z\d+\-.]*:/i.test(url)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat protocol-relative model URLs as absolute

normalizeModelCacheKey relies on isAbsoluteUrl, but the current regex only recognizes scheme-prefixed URLs and classifies protocol-relative URLs (//...) as relative. In that case the hostname is dropped (//cdn-a/x.glb and //cdn-b/x.glb both normalize to /x.glb), so load3DModel can reuse the wrong cached asset across different CDNs/hosts. This is a correctness bug whenever model URLs are provided in protocol-relative form.

Useful? React with 👍 / 👎.

@loong-solvable
Copy link
Copy Markdown
Author

Addressed the protocol-relative URL cache-key case from review. //cdn-a/... and //cdn-b/... now normalize to distinct absolute cache keys, with focused regression coverage in tests/load-model.test.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant