From db9b53462d9e61f85cd6d6246d7fd77bc5361163 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sat, 7 Dec 2024 15:38:17 +0100 Subject: [PATCH] fix(rendering and logging): remove extensive console chattiness, remove content memory leak when rerendering --- changelog.md | 5 +++++ ts/00_commitinfo_data.ts | 2 +- ts_web/00_commitinfo_data.ts | 2 +- ts_web/elements/contentinvoice.ts | 2 -- ts_web/elements/document.ts | 30 ++++++++++++++++++++++-------- ts_web/elements/page.ts | 2 -- ts_web/elements/pagecontent.ts | 2 -- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/changelog.md b/changelog.md index 08ee52b..b88c2b0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## 2024-12-07 - 1.6.8 - fix(rendering and logging) +Removed debug logging from document rendering process. + +- Removed console logs from content invoice, document rendering, page scaling, and overflow checking. + ## 2024-12-07 - 1.6.7 - fix(document rendering) Fixed overflow issues in document and page elements diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index b5628af..9e0bbea 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@design.estate/dees-document', - version: '1.6.7', + version: '1.6.8', description: 'A sophisticated framework for dynamically generating and rendering business documents like invoices with modern web technologies, featuring PDF creation, templating, and automation.' } diff --git a/ts_web/00_commitinfo_data.ts b/ts_web/00_commitinfo_data.ts index b5628af..9e0bbea 100644 --- a/ts_web/00_commitinfo_data.ts +++ b/ts_web/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@design.estate/dees-document', - version: '1.6.7', + version: '1.6.8', description: 'A sophisticated framework for dynamically generating and rendering business documents like invoices with modern web technologies, featuring PDF creation, templating, and automation.' } diff --git a/ts_web/elements/contentinvoice.ts b/ts_web/elements/contentinvoice.ts index ecc5ca4..2600a37 100644 --- a/ts_web/elements/contentinvoice.ts +++ b/ts_web/elements/contentinvoice.ts @@ -175,7 +175,6 @@ export class DeContentInvoice extends DeesElement { (await this.getContentNodes()).trimmedContent.append( (await this.getContentNodes()).currentContent.children.item(0) ); - console.log('hey' + this.shadowRoot.children.length); } if ( (await this.getContentNodes()).currentContent.children @@ -396,7 +395,6 @@ ${this.letterData.content.invoiceData.id} EPC QR Code`, (error) => { if (error) console.error(error); - console.log('success!'); } ); contentNodes.currentContent.querySelector('.paymentCode').append(canvas); diff --git a/ts_web/elements/document.ts b/ts_web/elements/document.ts index dd16eeb..a01748c 100644 --- a/ts_web/elements/document.ts +++ b/ts_web/elements/document.ts @@ -161,6 +161,7 @@ export class DeDocument extends DeesElement { public latestDocumentSettings: plugins.shared.interfaces.IDocumentSettings = null; public latestRenderedLetterData: plugins.tsclass.business.ILetter = null; + public cleanupStore: any[] = []; public async renderDocument() { @@ -168,11 +169,12 @@ export class DeDocument extends DeesElement { this.latestDocumentSettings = this.documentSettings; this.latestRenderedLetterData = this.letterData; - console.log(`rendering with settings:`); - console.log(this.latestDocumentSettings); + const cleanUpStoreCurrentRender = []; + const cleanUpStoreNextRender = []; const domtools = await this.domtoolsPromise; const documentBuildContainer = document.createElement('div'); + cleanUpStoreCurrentRender.push(documentBuildContainer); document.body.appendChild(documentBuildContainer); let pages: DePage[] = []; @@ -181,6 +183,7 @@ export class DeDocument extends DeesElement { // lets append the content const content: DeContentInvoice = new DeContentInvoice(); + cleanUpStoreCurrentRender.push(content); content.letterData = this.letterData; content.documentSettings = this.documentSettings; document.body.appendChild(content); @@ -192,6 +195,7 @@ export class DeDocument extends DeesElement { while (!complete) { pageCounter++; const currentContent = content.cloneNode(true) as DeContentInvoice; + cleanUpStoreNextRender.push(currentContent); const newPage = new DePage(); newPage.printMode = this.printMode; newPage.letterData = this.letterData; @@ -200,6 +204,9 @@ export class DeDocument extends DeesElement { newPage.pageNumber = pageCounter; newPage.append(currentContent); newPage.pageTotalNumber = pageCounter; + + // store current page + cleanUpStoreNextRender.push(newPage); documentBuildContainer.append(newPage); await currentContent.elementDomReady; @@ -216,16 +223,24 @@ export class DeDocument extends DeesElement { if (trimmed === 0) { complete = true; } - // complete = true; - console.log(currentContentOffset); } - document.body.removeChild(content); - document.body.removeChild(documentBuildContainer); + + for (const cleanUp of this.cleanupStore) { + cleanUp.remove(); + } + this.cleanupStore = cleanUpStoreNextRender + + cleanUpStoreCurrentRender.forEach((cleanUp) => { + cleanUp.remove(); + }); const documentContainer = this.shadowRoot.querySelector('.documentContainer'); if (documentContainer) { const children = Array.from(documentContainer.children); - children.forEach((child) => documentContainer.removeChild(child)); + children.forEach((child) => { + documentContainer.removeChild(child); + child.remove(); + }); } for (const page of pages) { page.pageTotalNumber = pageCounter; @@ -269,7 +284,6 @@ export class DeDocument extends DeesElement { } if (this.viewWidth) { page.viewWidth = this.viewWidth; - console.log('setting viewWidth: ', this.viewWidth); } }); } diff --git a/ts_web/elements/page.ts b/ts_web/elements/page.ts index 2ec73c6..c5d59b3 100644 --- a/ts_web/elements/page.ts +++ b/ts_web/elements/page.ts @@ -196,7 +196,6 @@ export class DePage extends DeesElement { } private adjustScaling() { - console.log('page scale adjustment triggered.'); const scaleWrapper: HTMLDivElement = this.shadowRoot.querySelector('#scaleWrapper'); if (!scaleWrapper) return; @@ -207,7 +206,6 @@ export class DePage extends DeesElement { } else if (this.viewWidth) { scale = this.viewWidth / plugins.shared.a4Width; } - console.log(`new scale is ${scale}`); scaleWrapper.style.transform = `scale(${scale})`; // Adjust the outer dimensions so they match the scaled content diff --git a/ts_web/elements/pagecontent.ts b/ts_web/elements/pagecontent.ts index 0cf8693..13f5de5 100644 --- a/ts_web/elements/pagecontent.ts +++ b/ts_web/elements/pagecontent.ts @@ -138,10 +138,8 @@ export class DePageContent extends DeesElement { await this.elementDomReady; const contentContainer = this.shadowRoot.querySelector('.content'); if (contentContainer.scrollHeight > contentContainer.clientHeight) { - console.log('overflows'); return true; } else { - console.log('does not overflow!'); return false; } }