-
-
Notifications
You must be signed in to change notification settings - Fork 180
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: Multiple instances of Component with Texture
via useAssets
#531
Comments
Would you mind adding a code snippet illustrating the issue for clarity? |
As an example take the following React Component: 'use client';
import { type FC, useCallback } from 'react';
import { useAssets } from '@pixi/react';
import type { Container, Graphics } from 'pixi.js';
export namespace Character {
export type Props = {
name: string;
config?: {
x?: number;
y?: number;
};
};
}
export const Character: FC<Character.Props> = ({
name,
config = { x: 0, y: 0 },
}) => {
const {
assets: [texture],
isSuccess,
} = useAssets([
{
alias: name,
src: `/${name}.webp`
},
]);
const drawWrapper = useCallback(
(graphics: Graphics) =>
graphics
.roundRect(0, 0, 40, 40, 6)
.fill({ 0x95af94 }),
[],
);
return (
<container
zIndex={2}
x={config.x ?? 0}
y={config.y ?? 0}
scale={1}
cursor='pointer'
eventMode='static'
>
<graphics zIndex={1} draw={drawWrapper} />
{isSuccess && (
<sprite
texture={texture}
width={40}
height={40}
zIndex={2}
anchor={0}
/>
)}
</container>
);
}; When calling this Component with a |
Thank you. Nice find! I have yet to run into this specifically, as I was loading the asset in the parent component and passing the loaded texture into the child component I mapped over. I can take a crack at adding a test case to https://github.com/pixijs/pixi-react/blob/beta/test/unit/hooks/useAssets.test.tsx. If you have any spare cycles and can capture the failure, it would greatly help expedite the fix. I can take over the failing PR. I'm about to go on vacation and will be able to take a look at the end of next week. |
No issues, so when using the |
Thanks for the repro; I will probably have to mock fetch, as my current test and mocks do not appear to fail when I attempt to fail the test. Must mock deeper into the mock abyss. |
Waiting on beta 13 🚀 |
I'm with beta 14 and this issue seems still present. I looked into the source code and the problem seems happen when const [state, setState] = useState<UseAssetsResult<T>>({
assets: Array(assets.length).fill(undefined),
isError: false,
isPending: true,
isSuccess: false,
status: UseAssetsStatus.PENDING,
});
...
const allAssetsAreLoaded = assets.some(assetsLoadedTest<T>);
if (!allAssetsAreLoaded) {
...
}
return state; Meanwhile, const { assets: [texture], isSuccess } = useAssets(["assets/pipe-green.png"]);
return (isSuccess && <sprite texture={texture} width={10} height={50} />); Works: const texture = useAsset("assets/pipe-green.png");
return (<sprite texture={texture} width={10} height={50} />); |
I can confirm this issue is quite blocking for pretty common use-cases. I'll just use the deprecated |
Current Behavior
When you have two Pixi components with a Sprite / Texture of the same URL, it doesn't show up when Mapped, I believe this is an issue with the underlying Cache.
Expected Behavior
N/A
Steps to Reproduce
N/A
Environment
@pixi/react
version: v8 Betapixi.js
version: v8React
version: 18.0.0ReactDOM
version: 18.0.0Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: