Skip to content

fix: cache load3DModel by normalized URL - #932

Open
MikeGarciaAGM wants to merge 3 commits into
tscircuit:mainfrom
MikeGarciaAGM:fix/load-model-cache-93
Open

fix: cache load3DModel by normalized URL#932
MikeGarciaAGM wants to merge 3 commits into
tscircuit:mainfrom
MikeGarciaAGM:fix/load-model-cache-93

Conversation

@MikeGarciaAGM

Copy link
Copy Markdown

Fixes #93

Summary

  • Add normalized URL cache keys for load3DModel, removing cachebust_origin, sorting query params, and dropping hash fragments.
  • Share in-flight/completed model loads for equivalent URLs so duplicate model paths do not re-fetch/re-parse through this utility path.
  • Return cloned object/material instances from the cache so rendered components do not share mutable Three.js material state.
  • Add regression tests for cache-key normalization.

Validation

  • npx bun test tests/load-model-cache-key.test.ts
  • npm run build

@vercel

vercel Bot commented May 31, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
3d-viewer Ready Ready Preview, Comment May 31, 2026 11:08am

Request Review

@rushabhcodes rushabhcodes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

proof?

@MikeGarciaAGM

Copy link
Copy Markdown
Author

Proof / verification:

  • Added regression coverage in tests/load-model-cache-key.test.ts.
  • Ran npx bun test tests/load-model-cache-key.test.ts -> 3 tests passed.
  • Ran npm run build -> passed.
  • Vercel preview check on this PR is green.

What the tests prove:

  1. equivalent model URLs with different cachebust_origin values share one loader call;
  2. query params are normalized so order does not create duplicate loads;
  3. callers receive cloned objects/materials, so shared cache state is not mutated across renders.

That directly covers the lag source from repeated cache-busted model loads while keeping each scene instance isolated.

@rushabhcodes rushabhcodes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not the fix, read the issue carefully

@MikeGarciaAGM

Copy link
Copy Markdown
Author

Follow-up fix pushed after review feedback: moved normalization to global OBJ loader path (use-global-obj-loader.ts), added global-obj-loader-cache-key tests, and re-ran build/tests on latest head 9a36200. Please re-review when you have a moment. Thanks.

@MikeGarciaAGM

Copy link
Copy Markdown
Author

Type-check/CI follow-up pushed for the failing checks.

Latest head: 1c3e53a

Verification run locally:

  • npx tsc --noEmit -> passed
  • npx biome format src/hooks/use-global-obj-loader.ts src/utils/load-model.ts tests/global-obj-loader-cache-key.test.ts tests/load-model-cache-key.test.ts -> passed
  • npm run build -> passed
  • npx bun test tests/load-model-cache-key.test.ts tests/global-obj-loader-cache-key.test.ts -> 6 passed

The patch only guards the normalized extension path against undefined and keeps the existing cache-key behavior/tests intact.

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.

Improve 3d model loading to avoid laggy browser

3 participants