Skip to content

[v9] fix(useLoader): localize url caching per loader#3243

Closed
CodyJasonBennett wants to merge 261 commits intomasterfrom
fix/useloader-localize-cache
Closed

[v9] fix(useLoader): localize url caching per loader#3243
CodyJasonBennett wants to merge 261 commits intomasterfrom
fix/useloader-localize-cache

Conversation

@CodyJasonBennett
Copy link
Copy Markdown
Member

@CodyJasonBennett CodyJasonBennett commented Apr 28, 2024

Follow-up to #3131 as per #3151 (comment). Related: mrdoob/three.js#27301.

krispya and others added 30 commits May 25, 2022 20:01
Co-authored-by: Gianmarco <gianmarcosimone89@gmail.com>
…ixedStages also has substepDeltas returning an array of deltas for each substep
…alues and now that we have deltas there are useland ways to hanlde this
@codesandbox-ci
Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 97c969f:

Sandbox Source
example Configuration

Comment on lines +136 to +137
// TODO: merge errors for multiple urls
throw new Error(`Could not load ${url}: ${(error as ErrorEvent)?.message}`)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Related: #3181

Base automatically changed from v9 to master February 19, 2025 13:19
@DennisSmolek
Copy link
Copy Markdown
Member

The items in this PR were merged in v9 it seems, reopen if im wrong but the code mentioned is in the codebase already

@DennisSmolek
Copy link
Copy Markdown
Member

Whoops. I mesread the memoizedLoaders as the memoized results. reopened

@DennisSmolek DennisSmolek added enhancement New feature or request v10 cleanup cleaning things labels Dec 22, 2025
@DennisSmolek
Copy link
Copy Markdown
Member

So I've gone a different way with this.
Suspend-react already has a cache (So does Three) this adds another cache of the response and a lot of our own overhead/handling.
Krispy also mentioned a different Cache setup.. I think if we want to enhance the cache we need to leverage the three cache, enhance suspend-react (we own that repo too) or drop it in favor of a more significant cache setup of our own.

In the meantime, to solve the key issue instead of passing the array of URLs to a single loadingFn/preload setup, I do the loop in the preload phase. (clear as well)

/**
 * Preloads an asset into cache as a side-effect.
 */
useLoader.preload = function <I extends InputLike, L extends LoaderLike | ConstructorRepresentation<LoaderLike>>(
  loader: L,
  input: I,
  extensions?: Extensions<L>,
): void {
  const keys = (Array.isArray(input) ? input : [input]) as string[]
  // Preload each key individually so cache keys match useLoader calls
  keys.forEach((key) => preload(loadingFn(extensions), [loader, key]))
}

This passes the exact key/pair to suspend-react so:

useLoader.preload(gltfLoader, [URL_A, URL_B])

function ComponentA() {
  const gltf = useLoader(gltfLoader, URL_A)
}

Now the pair [gltfLoader, URL_A] is the correct key and loads as expected.

I've also added a test for this usecase

See in v10

DennisSmolek added a commit to DennisSmolek/react-three-fiber that referenced this pull request Dec 26, 2025
@DennisSmolek DennisSmolek deleted the fix/useloader-localize-cache branch January 22, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup cleaning things enhancement New feature or request v10

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants