Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: useAssets might attempt state updates before mounting #566

Open
RJWadley opened this issue Jan 10, 2025 · 1 comment
Open

Bug: useAssets might attempt state updates before mounting #566

RJWadley opened this issue Jan 10, 2025 · 1 comment
Labels
v8 Issues related to Pixi React v8

Comments

@RJWadley
Copy link

Current Behavior

if the render is suspended after useAssets is called but before the image finishes loading, we get an error:

Image

Expected Behavior

useAssets should not cause errors if rendering is suspended

Steps to Reproduce

the easiest way to reproduce this is to create a component that suspends:

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

export function AssetTest() {
  const {
    assets: [texture],
    isSuccess,
  } = useAssets<Texture>([
    "https://fastly.picsum.photos/id/436/4000/4000.jpg?hmac=wzOFg9pak_9vNY9IF9Bz43cwQXdtmOGqXiWS-F9IzpY",
  ]);

  throw sleep(100);
  return null;
}

I've also prepared a codesandbox that throws this error. Note that you'll want to open the preview in a new tab because the codesandbox preview frame causes extra unrelated errors.

Environment

Possible Solution

  • the actual setState should probably go into an effect
  • in this case it's probably fine to start fetching the asset during the render - just don't update any react state
  • if the asset is already cached, it's fine to return it on the first render and skip the effect work later

Additional Information

No response

@trezy trezy added the v8 Issues related to Pixi React v8 label Jan 16, 2025
@thejustinwalsh
Copy link
Collaborator

thejustinwalsh commented Jan 20, 2025

@RJWadley thanks for catching this, I exclusivly have been using useSuspenseAssets with suspense, and never thought to run useAssets through a suspense test...

With React 19 out officially, I think we need to take a pass on simplifying the hooks and leaning on the new use hook. I don't beleive there needs to be a difference between the two hooks anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v8 Issues related to Pixi React v8
Projects
None yet
Development

No branches or pull requests

3 participants