Skip to content
Closed
Show file tree
Hide file tree
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
29 changes: 28 additions & 1 deletion packages/uix-host-react/src/components/Extensible.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe("Extensible", () => {
});
});

it("should not call unload if host was never created", () => {
it("should still create a host when extensions resolve empty, and unload it on unmount", async () => {
const extensionsProvider = jest.fn().mockResolvedValue({});

const { unmount } = render(
Expand All @@ -113,6 +113,33 @@ describe("Extensible", () => {
</Extensible>
);

// The host must exist even with zero extensions, so consumers relying on
// host readiness (e.g. useHost/loading state) aren't stuck waiting forever.
await waitFor(() => {
expect(MockedHost).toHaveBeenCalled();
});

// load() must not be called since there is nothing to load
expect(mockLoad).not.toHaveBeenCalled();

unmount();

await waitFor(() => {
expect(mockUnload).toHaveBeenCalled();
});
});

it("should not call unload if the extensions fetch never resolved before unmount", () => {
const extensionsProvider = jest
.fn()
.mockReturnValue(new Promise(() => {}));

const { unmount } = render(
<Extensible appName="test-app" extensionsProvider={extensionsProvider}>
<div>Test Child</div>
</Extensible>
);

unmount();

// Unload should not be called if host was never created
Expand Down
9 changes: 7 additions & 2 deletions packages/uix-host-react/src/components/Extensible.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,16 @@ export function Extensible({
};
}

if (!extensions || !Object.keys(extensions).length) {
if (!extensionListFetched) {
return;
}

const hasExtensions = !!extensions && !!Object.keys(extensions).length;

const loadExtensions = (hostInstance: Host) => {
if (!hasExtensions) {
return;
}
hostInstance
.load(extensions, guestOptions)
.catch(logError("Load of extensions failed!"));
Expand Down Expand Up @@ -220,7 +225,7 @@ export function Extensible({
} else {
loadExtensions(host);
}
}, [debug, hostName, runtimeContainer, extensions]);
}, [debug, hostName, runtimeContainer, extensions, extensionListFetched]);

const contextValue = useMemo(
() => ({ host, extensionListFetched }),
Expand Down
Loading