Skip to content

Commit ccd29d5

Browse files
Merge pull request #620 from spassvogel/main
fix initialization of extensions
2 parents 79728e1 + 96de464 commit ccd29d5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/components/Application.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
useContextBridge,
44
} from 'its-fine';
55
import {
6+
type ExtensionFormat,
67
type Application as PixiApplication,
78
extensions as PixiExtensions,
89
TextStyle,
@@ -45,7 +46,7 @@ const ApplicationImplementation = forwardRef<ApplicationRef, ApplicationProps>(f
4546

4647
const applicationRef: RefObject<PixiApplication | null> = useRef(null);
4748
const canvasRef = useRef<HTMLCanvasElement>(null);
48-
const extensionsRef = useRef<Set<any>>(new Set());
49+
const extensionsRef = useRef<Set<ExtensionFormat>>(new Set());
4950

5051
useImperativeHandle(forwardedRef, () => ({
5152
getApplication()
@@ -119,7 +120,7 @@ const ApplicationImplementation = forwardRef<ApplicationRef, ApplicationProps>(f
119120
}
120121

121122
// Load any remaining extensions.
122-
for (const extension in extensionsToHandle)
123+
for (const extension of extensionsToHandle)
123124
{
124125
PixiExtensions.add(extension);
125126
extensionsState.add(extension);

test/e2e/components/Application.test.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Application as PixiApplication } from 'pixi.js';
1+
import { Application as PixiApplication, extensions as PixiExtensions, ExtensionType } from 'pixi.js';
22
import {
33
createContext,
44
createRef,
@@ -195,4 +195,24 @@ describe('Application', () =>
195195
expect(roots.size).toEqual(0);
196196
});
197197
});
198+
199+
it('loads extensions provided in the extensions prop', async () =>
200+
{
201+
const customLoader = {
202+
extension: {
203+
type: ExtensionType.LoadParser,
204+
name: 'custom-loader',
205+
priority: 100,
206+
},
207+
};
208+
209+
const addSpy = vi.spyOn(PixiExtensions, 'add');
210+
211+
await act(async () => render((
212+
<Application extensions={[customLoader]} />
213+
)));
214+
215+
expect(addSpy).toHaveBeenCalledWith(customLoader);
216+
addSpy.mockRestore();
217+
});
198218
});

0 commit comments

Comments
 (0)