Skip to content
Source
Sign inSign up
TanStack/router

fix(start-plugin-core): write prerendered responses as bytes #8883

OpenEnesKartal(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/8883/headopened

Showing 3 changed files with 111 additions and 2 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/prerender-binary-bytes.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/start-plugin-core': patch
+---
+​
+fix: prerendering a server route that returns binary content (for example an image) now writes the response bytes unchanged instead of a UTF-8 re-encoded, corrupted file.
5 additions and 2 deletionspackages/start-plugin-core/src/prerender.tsModified
View file
@@ -190,7 +190,10 @@
routerBasePath,
​
- const html = await res.text()
+ // Read bytes: decoding to text would corrupt binary responses
+ // (images, PDFs, ...) before they are written to disk.
+ const body = new Uint8Array(await res.arrayBuffer())
+ const html = new TextDecoder().decode(body)
const resolvedOutputDir = path.resolve(outputDir)
const filepath = path.resolve(outputDir, filename.replace(/^\/+/, ''))
const outputPrefix = resolvedOutputDir.endsWith(path.sep)
@@ -209,7 +212,7 @@
recursive: true,
​
- await fsp.writeFile(filepath, html)
+ await fsp.writeFile(filepath, body)
​
prerendered.add(page.path)
​