Skip to content

Commit

Permalink
fixed memory leak (#2831) (#2833) (#2835)
Browse files Browse the repository at this point in the history
  • Loading branch information
Omri-Levy authored Nov 12, 2024
1 parent a621cc5 commit 195805e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
6 changes: 3 additions & 3 deletions apps/backoffice-v2/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import '@ballerine/ui/dist/style.css';
import '@fontsource/inter';

import { Toaster } from '@/common/components/organisms/Toaster/Toaster';
import { registerFont } from '@ballerine/react-pdf-toolkit';
import { Font } from '@react-pdf/renderer';
// Uncomment once react-pdf is back in use
// import { Font } from '@react-pdf/renderer';
import { Router } from './Router/Router';
import { env } from './common/env/env';
import './i18n';
Expand All @@ -24,7 +24,7 @@ initializeSessionRecording();

dayjs.extend(advancedFormat);

registerFont(Font);
// registerFont(Font);

export const TOAST_DURATION_IN_MS = 1000 * 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const CaseOptions = () => {
<DropdownMenuItem className="w-full px-8 py-1" asChild>
<Button
onClick={() => generateAndOpenPDFInNewTab()}
disabled={isGeneratingPDF}
// disabled={isGeneratingPDF}
disabled
variant={'ghost'}
className="justify-start"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TWorkflowById } from '@/domains/workflows/fetchers';
import { TCustomer } from '@/domains/customer/fetchers';
import { useMutation } from '@tanstack/react-query';
import { TitlePagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf';
import { RegistryPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf';
import { CompanyOwnershipPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf';
import { CompanySanctionsPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf';
import { IdentityVerificationsPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf';
import { IndividualSantcionsPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf';
import { Document, pdf } from '@react-pdf/renderer';
// import { TitlePagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/title-page.pdf';
// import { RegistryPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/registry-page.pdf';
// import { CompanyOwnershipPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-ownership-page.pdf';
// import { CompanySanctionsPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/company-sanctions-page.pdf';
// import { IdentityVerificationsPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/identity-verifications-page.pdf';
// import { IndividualSantcionsPagePDF } from '@/pages/Entity/components/Case/components/CaseOptions/hooks/useCaseOptionsLogic/renderers/individual-sanctions-page.pdf';
// import { Document, pdf } from '@react-pdf/renderer';
import { toast } from 'sonner';
import { t } from 'i18next';

Expand All @@ -29,21 +29,22 @@ export const useGeneratePDFMutation = ({
customer: TCustomer;
}) => {
return useMutation({
// Temporarily disabled until react-pdf no longer has memory leaks
mutationFn: async () => {
const pdfs = [
TitlePagePDF,
RegistryPagePDF,
CompanyOwnershipPagePDF,
CompanySanctionsPagePDF,
IdentityVerificationsPagePDF,
IndividualSantcionsPagePDF,
];
const renderers = pdfs.map(PDF => new PDF(workflow, customer));
const pages = await Promise.all(renderers.map(renderer => renderer.render()));

const pdfBlob = await pdf(<Document>{pages}</Document>).toBlob();

openBlobInNewTab(pdfBlob);
// const pdfs = [
// TitlePagePDF,
// RegistryPagePDF,
// CompanyOwnershipPagePDF,
// CompanySanctionsPagePDF,
// IdentityVerificationsPagePDF,
// IndividualSantcionsPagePDF,
// ];
// const renderers = pdfs.map(PDF => new PDF(workflow, customer));
// const pages = await Promise.all(renderers.map(renderer => renderer.render()));
//
// const pdfBlob = await pdf(<Document>{pages}</Document>).toBlob();
//
// openBlobInNewTab(pdfBlob);
},
onError: error => {
console.error(`Failed to open PDF certificate: ${JSON.stringify(error)}`);
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations

0 comments on commit 195805e

Please sign in to comment.