mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 00:12:39 +00:00
fix: start plugins when the sign-in races the first plugin start
This commit is contained in:
@@ -287,6 +287,20 @@ describe('usePluginStore', () => {
|
||||
expect(usePluginStore.getState().initialized).toBe(true);
|
||||
});
|
||||
|
||||
it('starts the plugins when a call made after the sign-in joined the signed-out one', async () => {
|
||||
const { loadPlugin } = await import('@/lib/plugin-loader');
|
||||
let answer!: (r: unknown) => void;
|
||||
mocks.apiFetch.mockImplementationOnce(() => new Promise((r) => { answer = r; }));
|
||||
|
||||
const beforeSignIn = usePluginStore.getState().initializePlugins();
|
||||
const afterSignIn = usePluginStore.getState().initializePlugins();
|
||||
answer({ ok: false, status: 401, json: async () => ({}) });
|
||||
await Promise.all([beforeSignIn, afterSignIn]);
|
||||
|
||||
expect(loadPlugin).toHaveBeenCalledWith(expect.objectContaining({ id: 'managed-plugin' }));
|
||||
expect(usePluginStore.getState().initialized).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps the record when the download fails so the error can surface at load time', async () => {
|
||||
usePluginStore.setState({ plugins: [syncedRecord()] });
|
||||
mocks.downloadManagedBundle.mockRejectedValue(new Error('Could not download the bundle (HTTP 503)'));
|
||||
|
||||
@@ -317,7 +317,11 @@ export const usePluginStore = create<PluginStoreState>()(
|
||||
if (get().initialized) return;
|
||||
|
||||
if (pluginInitializationPromise) {
|
||||
await pluginInitializationPromise;
|
||||
const joined = pluginInitializationPromise;
|
||||
await joined;
|
||||
// The run this joined may have ended signed out (it started before
|
||||
// the sign-in); then this call starts the plugins itself.
|
||||
if (!get().initialized && pluginInitializationPromise !== joined) await get().initializePlugins();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user