fix: use renderToBuffer to fix resume download (#89)#124
Conversation
pdf().toBuffer() returns a PDFDocument object, not a Buffer, causing the Response to receive unusable data and throw 'Failed to generate resume'. Fix: - Replace pdf() with renderToBuffer() from @react-pdf/renderer which correctly returns a Node.js Buffer on the server side - Remove @ts-expect-error hack in route.ts since Buffer is now valid - Use anchor tag download instead of window.open() to avoid popup blockers - Show user-facing alert on failure instead of silent console.error Fixes sunithvs#89
|
Someone is attempting to deploy a commit to the lamsta Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Code Review
This pull request refactors the resume generation and download flow. It updates the API route to directly return a PDF buffer generated via renderToBuffer instead of using the pdf instance, removing an unused @ts-expect-error comment. On the client side, the resume button is updated to trigger a direct file download instead of opening the PDF in a new tab, and basic error handling with an alert is added. The reviewer suggested appending the temporary anchor element to the DOM before clicking it to ensure cross-browser compatibility (e.g., in Firefox).
|
Thanks @gemini-code-assist! Fixed in 3baacda — the anchor is now appended to |
|
That sounds like a solid approach for ensuring the download trigger is handled correctly across different browsers. Since you've already verified the fix and confirmed cross-browser compatibility, this looks good to go. Nice work resolving the |
Problem
The "Download Resume" button fails with
Error: Failed to generate resumebecausepdf().toBuffer()from@react-pdf/rendererreturns aPDFDocumentobject, not a Node.jsBuffer. Passing this tonew Response()results in an unusable response body.Fix
pdf(<Doc />).toBuffer()withrenderToBuffer(<Doc />)— the correct server-side API that returns a realBuffer@ts-expect-errorhack inroute.ts(no longer needed)<a download>instead ofwindow.open()to avoid popup blockersalerton failure instead of silentconsole.errorTesting
cd www && npm install && npm run devhttp://localhost:3000/<any-github-username>http://localhost:3000/api/resume?username=torvaldsdirectly — should return a PDF fileFixes #89