Skip to content

fix: use renderToBuffer to fix resume download (#89)#124

Open
Dawn-Fighter wants to merge 2 commits into
sunithvs:mainfrom
Dawn-Fighter:fix/resume-download-tobuffer
Open

fix: use renderToBuffer to fix resume download (#89)#124
Dawn-Fighter wants to merge 2 commits into
sunithvs:mainfrom
Dawn-Fighter:fix/resume-download-tobuffer

Conversation

@Dawn-Fighter
Copy link
Copy Markdown

Problem

The "Download Resume" button fails with Error: Failed to generate resume because pdf().toBuffer() from @react-pdf/renderer returns a PDFDocument object, not a Node.js Buffer. Passing this to new Response() results in an unusable response body.

Fix

  • Replace pdf(<Doc />).toBuffer() with renderToBuffer(<Doc />) — the correct server-side API that returns a real Buffer
  • Remove the @ts-expect-error hack in route.ts (no longer needed)
  • Use <a download> instead of window.open() to avoid popup blockers
  • Show user-facing alert on failure instead of silent console.error

Testing

  1. Run cd www && npm install && npm run dev
  2. Visit http://localhost:3000/<any-github-username>
  3. Click the Download Resume button — PDF should download directly
  4. Also test http://localhost:3000/api/resume?username=torvalds directly — should return a PDF file

Fixes #89

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
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 27, 2026

Someone is attempting to deploy a commit to the lamsta Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread www/components/ClientResumeButton.tsx
@Dawn-Fighter
Copy link
Copy Markdown
Author

Thanks @gemini-code-assist! Fixed in 3baacda — the anchor is now appended to document.body before clicking and removed immediately after, ensuring cross-browser compatibility including Firefox.

@gemini-code-assist
Copy link
Copy Markdown

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 renderToBuffer issue and cleaning up the @ts-expect-error hack!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Download Resume option is not working

1 participant