fix(rendering and logging): remove extensive console chattiness, remove content memory leak when rerendering

This commit is contained in:
Philipp Kunz 2024-12-07 15:38:17 +01:00
parent dbca81987c
commit db9b53462d
7 changed files with 29 additions and 16 deletions

View File

@ -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

View File

@ -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.'
}

View File

@ -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.'
}

View File

@ -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);

View File

@ -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);
}
});
}

View File

@ -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

View File

@ -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;
}
}