fix: start plugins when the sign-in races the first plugin start

This commit is contained in:
Linus Rath
2026-10-25 02:24:41 +01:00
parent 5edbbf0816
commit f20892ccec
2 changed files with 19 additions and 1 deletions
+14
View File
@@ -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)'));
+5 -1
View File
@@ -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;
}