Git Product home page Git Product logo

Comments (3)

NathanaelA avatar NathanaelA commented on June 21, 2024 1

Awesome, thanks for the confirmation. I'll upload a new version of the code as that monkey patching should actually have been safeguarded to make sure people can't accidentally do what you did. Thanks for the report and it is now fixed in v1.4.1

from fluentreports.

NathanaelA avatar NathanaelA commented on June 21, 2024

Your issue is very weird. There are two possibilities I can think of (the second being more likely)...

And yes, you are correct this code just eliminates basically empty stuff, however I think w/o the _finalize code you might randomly get output glitches occasionally as null offsets would probably be translated to 0,0 offsets...

  1. Can you tell me which version of PDFKit that you are using, maybe an upstream change in it broke something...

  2. The main thing I can think of is that somehow the FluentReports.pdfkit.js overrides is being initialized multiple times and replacing _end & _finalize a second time in the PDFKit, which would for sure create a loop like you are seeing.
    Could you be using two different copies of FluentReports or perhaps FR is npm installed in two (or more) directories, or perhaps their is some weird issue with bundling or node that is causing the fluentreports.pdfkit.js to be loaded a second time. In any case, changing the code in all copies of fluentreports/lib/fluentReports.pdfkit.js to the following should eliminate that possibility...

if (!pdfkit.prototype._PKIEnd) {
 pdfkit.prototype._PKIEnd = pdfkit.prototype.end;

  pdfkit.prototype.end = function () {
     if (this.isEmptyPage()) {
         this.deletePage();
     }
     this._PKIEnd();
 };
}

if (!pdfkit.prototype._PKIFinalize) {
 pdfkit.prototype._PKIFinalize = pdfkit.prototype._finalize;
 pdfkit.prototype._finalize = function (fn) {
     let i = 0;
     while (i < this._offsets.length) {
         // Eliminate any NULL Offsets from deleted pages
         if (this._offsets[i] === null) {
             this._offsets.splice(i, 1);
             continue;
         }
         i++;/
     }
     this._PKIFinalize(fn);
 };
}

from fluentreports.

97andrewvaldez avatar 97andrewvaldez commented on June 21, 2024

Thanks for the quick response. That code snippet worked!

It also prompted me to test a bit more to see if I could optimize how those routes are loading.

I found that using
const Report = require('fluentReports').Report;
at the top of my report generation files caused the overrides to be initialized in each file (then would later cause the stack overflow).

then replacing
const Report = require('fluentReports').Report;
with
import { Report } from 'fluentReports';
fixed the issue without your code changes.

FluentReports was up to date and using pdfkit .13 - for reference I also tried previous versions of fluentreports that used pdfkit .12 and .11 but had the same issue. Also pdfkit isn't installed anywhere else in our lock file so no conflicts there.

Either way that helped solve things, and eased my mind a bit 😄 thanks again!

from fluentreports.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.