Skip to content
Closed
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
import { createContext, type ReactNode, type PropsWithChildren } from 'react';
import {
createContext,
type ReactNode,
type PropsWithChildren,
useState,
useEffect,
} from 'react';
import {
createContext,
type ReactNode,
type PropsWithChildren,
useState,
useEffect,
} from 'react';
import type ApplicationInstance from '@ember/application/instance';

interface ApplicationProviderProps extends PropsWithChildren {
Expand All @@ -13,6 +26,20 @@ export function ApplicationProvider({
owner,
children,
}: ApplicationProviderProps): ReactNode {
const [isDestroyed, setIsDestroyed] = useState<boolean>(false);

useEffect(() => {
const oldWillDestroy = owner.willDestroy;
owner.willDestroy = (...args) => {
setIsDestroyed(true);
oldWillDestroy.apply(owner, args);
};
}, [owner]);

if (isDestroyed) {
return null;
}

return (
<ApplicationContext.Provider value={owner}>
{children}
Expand Down