Generate file: PDF export fails for empty arrays and table data
Version Information
Upstream main at 3f5350c5e0dafb76b25c743dca42d37c48bd6d3d. The affected helper is also identical on current lts-3.16.
Environment
Public frontend source on Linux, Node.js 22.15.1, with the lockfile versions of jsPDF (4.2.0) and jsPDF-AutoTable (5.0.7).
The failures below were reproduced by executing the unchanged helper with the real PDF libraries and intercepting save() to observe whether a PDF was produced. A full ToolJet browser session has not yet been tested.
What is the expected behaviour?
The Generate file action should download a PDF for the documented string and array-of-objects inputs. An empty query result should complete the export as a blank PDF with the requested filename.
What is the current behaviour?
- Empty array:
TypeError: Cannot convert undefined or null to object. - Nonempty array of objects:
TypeError: doc.autoTable is not a function. - A single object, which the helper also handles, produces the same AutoTable error.
- String input successfully generates a PDF.
Neither failing path reaches save().
How to reproduce the issue?
Call the existing default export from frontend/src/_lib/generate-file.js with:
await generateFile('empty.pdf', [], 'pdf');
await generateFile('rows.pdf', [{ name: 'Ada', count: 1 }], 'pdf');
await generateFile('text.pdf', 'Report', 'pdf'); // working controlThe corresponding application action is actions.generateFile('rows.pdf', 'pdf', [{ name: 'Ada', count: 1 }]). Test it in a fresh editor or released-app session without first using the Table component's PDF export.
Cause and proposed fix
The array branch reads Object.keys(value[0]) without handling an empty array. Both table branches call doc.autoTable(), but this helper only imports jspdf; it never loads or applies AutoTable.
The existing Table exporter already provides a suitable pattern: lazily import both packages and call the exported autoTable(doc, options) function explicitly. Apply that pattern here, skip table rendering for empty arrays while still saving the document, and add focused regression tests. Preserve the current action interface and CSV/text behavior; no dependency changes are needed.
Prior report and assignment request
The empty-array failure was reported by @PedroHenrique0713 in #17269, which was closed without review. The author recently invited focused follow-ups. This report isolates the PDF action and includes the additional reproducible AutoTable failure.
I'd like to work on this focused fix, with regression tests and a brief documentation note. Could a maintainer confirm the scope and assign it to me? I'll wait for assignment before coding, per the contribution guide.
Source: ToolJet/ToolJet