Skip to content

Commit 49f5a39

Browse files
committed
use buffered body if available, otherwise buffer
1 parent 649de2a commit 49f5a39

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

packages/kit/src/core/adapt/prerender/prerender.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
193193
}
194194

195195
for (const [dependency_path, result] of dependencies) {
196-
const response_type = Math.floor(result.status / 100);
196+
const { status, headers } = result.response;
197197

198-
const is_html = result.headers.get('content-type') === 'text/html';
198+
const response_type = Math.floor(status / 100);
199+
200+
const is_html = headers.get('content-type') === 'text/html';
199201

200202
const parts = dependency_path.split('/');
201203
if (is_html && parts[parts.length - 1] !== 'index.html') {
@@ -205,16 +207,17 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
205207
const file = `${out}${parts.join('/')}`;
206208
mkdirp(dirname(file));
207209

208-
if (result.body) {
209-
writeFileSync(file, result.body);
210-
paths.push(dependency_path);
211-
}
210+
writeFileSync(
211+
file,
212+
result.body === null ? new Uint8Array(await result.response.arrayBuffer()) : result.body
213+
);
214+
paths.push(dependency_path);
212215

213216
if (response_type === OK) {
214-
log.info(`${result.status} ${dependency_path}`);
217+
log.info(`${status} ${dependency_path}`);
215218
} else {
216219
error({
217-
status: result.status,
220+
status,
218221
path: dependency_path,
219222
referrer: path,
220223
referenceType: 'fetched'

packages/kit/src/runtime/server/page/load_node.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ export async function load_node({
163163
if (rendered) {
164164
if (state.prerender) {
165165
dependency = {
166-
status: rendered.status,
167-
headers: rendered.headers
166+
response: rendered,
167+
body: null
168168
};
169169

170170
state.prerender.dependencies.set(resolved, dependency);

packages/kit/types/internal.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { ExternalFetch, GetSession, HandleError, InternalHandle, RequestEvent }
66
import { Load } from './page';
77

88
export interface PrerenderDependency {
9-
status: number;
10-
headers: Headers;
11-
body?: string | Uint8Array;
9+
response: Response;
10+
body: null | string | Uint8Array;
1211
}
1312

1413
export interface PrerenderOptions {

0 commit comments

Comments
 (0)