Skip to content

Commit 7cc1c22

Browse files
committed
reset prerender
1 parent 21503ef commit 7cc1c22

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

packages/start-plugin-core/src/prerender.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,21 @@ export async function prerender({
8989
path: string,
9090
options?: RequestInit,
9191
maxRedirects: number = 5,
92-
wasRedirected: boolean = false,
93-
): Promise<{ response: Response; wasRedirected: boolean; finalPath: string }> {
92+
): Promise<Response> {
9493
const url = new URL(`http://localhost${path}`)
9594
const response = await serverEntrypoint.fetch(new Request(url, options))
9695

9796
if (isRedirectResponse(response) && maxRedirects > 0) {
9897
const location = response.headers.get('location')!
9998
if (location.startsWith('http://localhost') || location.startsWith('/')) {
10099
const newUrl = location.replace('http://localhost', '')
101-
return localFetch(newUrl, options, maxRedirects - 1, true)
100+
return localFetch(newUrl, options, maxRedirects - 1)
102101
} else {
103102
logger.warn(`Skipping redirect to external location: ${location}`)
104103
}
105104
}
106105

107-
return {
108-
response,
109-
wasRedirected,
110-
finalPath: path,
111-
}
106+
return response
112107
}
113108

114109
try {
@@ -141,7 +136,6 @@ export async function prerender({
141136
async function prerenderPages({ outputDir }: { outputDir: string }) {
142137
const seen = new Set<string>()
143138
const prerendered = new Set<string>()
144-
const writtenFiles = new Set<string>()
145139
const retriesByPath = new Map<string, number>()
146140
const concurrency = startConfig.prerender?.concurrency ?? os.cpus().length
147141
logger.info(`Concurrency: ${concurrency}`)
@@ -186,7 +180,7 @@ export async function prerender({
186180
// Fetch the route
187181
const encodedRoute = encodeURI(page.path)
188182

189-
const { response: res, wasRedirected, finalPath } = await localFetch(
183+
const res = await localFetch(
190184
withBase(encodedRoute, routerBasePath),
191185
{
192186
headers: {
@@ -205,14 +199,8 @@ export async function prerender({
205199
})
206200
}
207201

208-
// Use the final path (after redirects) for determining output location
209-
const pathForOutput = wasRedirected ? finalPath : page.path
210-
if (wasRedirected) {
211-
logger.info(`Page ${page.path} redirected to ${finalPath}, using final path for output`)
212-
}
213-
214202
const cleanPagePath = (
215-
prerenderOptions.outputPath || pathForOutput
203+
prerenderOptions.outputPath || page.path
216204
).split(/[?#]/)[0]!
217205

218206
// Guess route type and populate fileName
@@ -240,20 +228,12 @@ export async function prerender({
240228

241229
const filepath = path.join(outputDir, filename)
242230

243-
// Skip writing if this file path has already been written
244-
// This prevents URLs with different query params from overwriting each other
245-
if (writtenFiles.has(filename)) {
246-
logger.info(`Skipping write for ${page.path} - file ${filename} already written`)
247-
return
248-
}
249-
250231
await fsp.mkdir(path.dirname(filepath), {
251232
recursive: true,
252233
})
253234

254235
await fsp.writeFile(filepath, html)
255236

256-
writtenFiles.add(filename)
257237
prerendered.add(page.path)
258238

259239
const newPage = await prerenderOptions.onSuccess?.({ page, html })
@@ -330,4 +310,4 @@ export async function writeBundleToDisk({
330310

331311
await fsp.writeFile(fullPath, content)
332312
}
333-
}
313+
}

0 commit comments

Comments
 (0)