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

Destroy application on unmount #542

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
504aaa9
fix: make Application children optional
trezy Sep 2, 2024
58c58f7
Merge branch 'beta' into 521-bug-v8-memoized-component-renders-after-…
trezy Sep 3, 2024
b91fa7e
fix: handle unmounting `<Application>`
trezy Sep 3, 2024
110ba3d
test: add test for `<Application>`s `onInit`
trezy Sep 3, 2024
6ac48ac
ci: temp disable dev publish
trezy Sep 3, 2024
b370e5a
test: test `<Application>` unmounts
trezy Sep 3, 2024
e0b6e4b
chore: rename `unmountApplications` to `processUnmountedQueue` for cl…
trezy Sep 4, 2024
14635f1
chore: remove unnecessary optional operator
trezy Sep 4, 2024
62aae0b
chore: code style
trezy Sep 4, 2024
6429bb4
test: update `useTick` tests to use `expect.poll`
trezy Sep 4, 2024
f429cd6
chore: remove unused test util
trezy Sep 4, 2024
8e2ad70
refactor: check app state instead of eating the destroy error
trezy Sep 4, 2024
e629827
refactor: use a Set for unmount queue
trezy Sep 4, 2024
2592a34
refactor: rename `unmountApplication` to `unmountRoot` for clarity
trezy Sep 4, 2024
57434d8
test: improve unmounted app check
trezy Sep 4, 2024
78d6b96
test: verify applications are removed from the roots cache after unmount
trezy Dec 26, 2024
4d8f15b
fix: make sure applications always have a canvas in internal state
trezy Dec 26, 2024
53cddcd
build: update import attributes
trezy Dec 26, 2024
95197dd
build: remove unused dep
trezy Dec 26, 2024
4fc621b
ci: disable bin rebuild
trezy Dec 26, 2024
f3cc9e5
Merge branch 'beta' into 521-bug-v8-memoized-component-renders-after-…
trezy Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: improve unmounted app check
  • Loading branch information
trezy committed Sep 4, 2024
commit 57434d80d3c431e41fd8c860b59216cb74b4fd79
5 changes: 3 additions & 2 deletions test/e2e/components/Application.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { render } from '@testing-library/react';
import { useEffect } from 'react';

import { Application } from '../../../src/components/Application';
import { isAppMounted } from '../../utils/isAppMounted';
import { useApplication } from '../../../src/hooks/useApplication';

describe('Application', () => {
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('Application', () => {

unmount();

await expect.poll(() => Boolean(testApp.renderer && testApp.stage)).toBeFalsy();
await expect.poll(() => isAppMounted(testApp)).toBeFalsy();
});

it('unmounts during init', async () => {
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('Application', () => {

unmount();

await expect.poll(() => Boolean(testApp.renderer && testApp.stage)).toBeFalsy();
await expect.poll(() => isAppMounted(testApp)).toBeFalsy();
});
});
});
19 changes: 19 additions & 0 deletions test/utils/getAppRoot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { type Application as PixiApplication } from 'pixi.js';
import { roots } from '../../src/core/roots';
import { type Root } from '../../src/typedefs/Root';

export function getAppRoot(app: PixiApplication)
{
let root: Root | undefined;

for (const oRoot of roots.values())
{
if (oRoot.applicationState.app === app)
{
root = oRoot;
break;
}
}

return root;
}
22 changes: 22 additions & 0 deletions test/utils/isAppMounted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { type Application as PixiApplication } from 'pixi.js';
import { getAppRoot } from './getAppRoot';

export function isAppMounted(app: PixiApplication)
{
if (app.stage === null)
{
return false;
}

if (app.renderer === null)
{
return false;
}

if (typeof getAppRoot(app) === 'undefined')
{
return false;
}

return true;
}