Skip to content
Open
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
5 changes: 5 additions & 0 deletions rspack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export default defineConfig({
requiredVersion: pkg.dependencies['vue-i18n'],
eager: true,
},
pinia: {
singleton: true,
requiredVersion: pkg.dependencies.pinia,
eager: true,
},
},
}),
],
Expand Down
1 change: 1 addition & 0 deletions src/api/requests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import '@/utils/piniaSetup';
import type { AxiosInstance } from 'axios';
import camelcaseKeys from 'camelcase-keys';
import { useAuthStore } from '@/stores/auth';
Expand Down
30 changes: 12 additions & 18 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import { moduleStorage } from './utils/storage';

import { safeImport, isFederatedModule } from './utils/moduleFederation';

const { useSharedStore } = await safeImport(
() => import('connect/sharedStore'),
'connect/sharedStore',
);

const sharedStore = useSharedStore?.();

interface MountBulkSendAppOptions {
containerId?: string;
initialRoute?: string;
Expand Down Expand Up @@ -59,23 +66,10 @@ export default async function mountBulkSendApp({
return { app: appRef, router };
}

// Handle sharedStore asynchronously without blocking app mount
safeImport(() => import('connect/sharedStore'), 'connect/sharedStore')
.then((module) => {
if (module.useSharedStore && isFederatedModule) {
const sharedStore = module.useSharedStore();
if (sharedStore) {
moduleStorage.setItem('authToken', sharedStore.auth.token);
moduleStorage.setItem('projectUuid', sharedStore.current.project.uuid);
}
}
})
.catch((e) => {
console.log('[BulkSend - main.ts] Error importing shared store', e);
// Ignore errors - app should work without sharedStore
});

// Always mount the app if it's not a federated module
if (!isFederatedModule) {
if (sharedStore && isFederatedModule) {
moduleStorage.setItem('authToken', sharedStore.auth.token);
moduleStorage.setItem('projectUuid', sharedStore.current.project.uuid);
} else {
console.log('[BulkSend - main.ts] Mounting app not federated');
mountBulkSendApp();
}
16 changes: 16 additions & 0 deletions src/utils/piniaSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createPinia, setActivePinia, getActivePinia } from 'pinia';

export function setupPinia() {
let pinia = getActivePinia();

//Pinia is initialized for the federated module
if (!pinia) {
pinia = createPinia();
setActivePinia(pinia);
}

console.log('[BulkSend - piniaSetup.ts] Pinia initialized', pinia);
return pinia;
}

setupPinia();
Loading